ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2024-10-07 08:26:43
Exec Total Coverage
Lines: 2790 8298 33.6%
Functions: 77 292 26.4%
Branches: 2417 7188 33.6%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "dialog/info.h"
12 #include "metadata/metadata.h"
13
14 #include "base/qrs.h"
15 #include "base/dmap.h"
16 #include "base/packfile.h"
17 #include "base/cpool.h"
18 #include "base/autocombo.h"
19 #include "base/gui.h"
20 #include "base/msgstr.h"
21 #include "zc/zelda.h"
22 #include "zq/zq_class.h"
23 #include "zq/zq_misc.h"
24 #include "zq/zquest.h"
25 #include "base/qst.h"
26 #include "base/colors.h"
27 #include "tiles.h"
28 #include "zq/zquestdat.h"
29 #include "base/zsys.h"
30 #include "sprite.h"
31 #include "items.h"
32 #include "zc/zc_sys.h"
33 #include "md5.h"
34 #include "zc/zc_custom.h"
35 #include "subscr.h"
36 #include "zq/zq_strings.h"
37 #include "zq/zq_subscr.h"
38 #include "zc/ffscript.h"
39 #include "base/util.h"
40 #include "zq/zq_files.h"
41 #include "dialog/alert.h"
42 #include "slopes.h"
43 #include "drawing.h"
44 #include "zinfo.h"
45 #include "zq/render_minimap.h"
46 #include "base/mapscr.h"
47 #include <fmt/format.h>
48 #include <filesystem>
49
50 #ifdef __EMSCRIPTEN__
51 #include "base/emscripten_utils.h"
52 #endif
53
54 namespace fs = std::filesystem;
55
56 using namespace util;
57
58 extern ZModule zcm;
59 extern zcmodule moduledata;
60 extern uint8_t ViewLayer3BG, ViewLayer2BG;
61 extern int32_t LayerDitherBG, LayerDitherSz;
62 extern bool NoHighlightLayer0;
63
64 using std::string;
65 using std::pair;
66 #define EPSILON 0.01 // Define your own tolerance
67 #define FLOAT_EQ(x,v) (((v - EPSILON) < x) && (x <( v + EPSILON)))
68
69 #define COLOR_SOLID vc(4)
70 #define COLOR_SLOPE vc(13)
71 #define COLOR_LADDER vc(6)
72 //#define COLOR_EFFECT vc(10)
73
74 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
75 extern char msgbuf[MSG_NEW_SIZE*8];
76
77 extern string zScript;
78
79 9 zmap Map;
80 int32_t prv_mode=0;
81 int16_t ffposx[MAXFFCS];
82 int16_t ffposy[MAXFFCS];
83 int32_t ffprvx[MAXFFCS];
84 int32_t ffprvy[MAXFFCS];
85 void init_ffpos()
86 {
87 for (word q = 0; q < MAXFFCS; ++q)
88 {
89 ffposx[q] = -1000;
90 ffposy[q] = -1000;
91 ffprvx[q] = -10000000;
92 ffprvy[q] = -10000000;
93 }
94 }
95
96 bool save_warn=true;
97
98 int32_t COMBOPOS(int32_t x, int32_t y)
99 {
100 return (((y) & 0xF0) + ((x) >> 4));
101 }
102 int32_t COMBOPOS_B(int32_t x, int32_t y)
103 {
104 if(unsigned(x) >= 256 || unsigned(y) >= 176)
105 return -1;
106 return COMBOPOS(x,y);
107 }
108 int32_t COMBOX(int32_t pos)
109 {
110 return ((pos) % 16 * 16);
111 }
112 int32_t COMBOY(int32_t pos)
113 {
114 return ((pos) & 0xF0);
115 }
116
117 void reset_dmap(int32_t index)
118 {
119 bound(index,0,MAXDMAPS-1);
120 DMaps[index].clear();
121 DMaps[index].title = "";
122 sprintf(DMaps[index].intro, " ");
123 }
124
125 void reset_dmaps()
126 {
127 for(int32_t i=0; i<MAXDMAPS; i++)
128 reset_dmap(i);
129 }
130
131 void truncate_dmap_title(std::string& title)
132 {
133 title.resize(21, ' ');
134 }
135
136 mapscr* zmap::get_prvscr()
137 {
138 return &prvscr;
139 }
140
141
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 zmap::zmap()
142 {
143 18 can_paste=false;
144 18 prv_cmbcycle=0;
145 18 prv_advance=0;
146 18 prv_freeze=0;
147 18 copyffc=-1;
148
149 18 memset(scrpos, 0, sizeof(scrpos));
150 18 memset(scrview, 0, sizeof(scrview));
151 18 screens=NULL;
152 18 prv_time=0;
153 18 prv_scr=0;
154 18 prv_map=0;
155 18 copyscr=0;
156 18 cursor={};
157 copymap=0;
158 layer_target_map = 0;
159 layer_target_scr = 0;
160 layer_target_multiple = 0;
161 18 }
162
163 9 void zmap::clear()
164 {
165
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 *this = zmap();
166 9 }
167 void zmap::force_refr_pointer()
168 {
169 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
170 screens = nullptr;
171 else screens = &TheMaps[cursor.map*MAPSCRS];
172 }
173 bool zmap::CanUndo()
174 {
175 return undo_stack.size() > 0;
176 }
177 bool zmap::CanRedo()
178 {
179 return redo_stack.size() > 0;
180 }
181 bool zmap::CanPaste()
182 {
183 return can_paste;
184 }
185 int32_t zmap::CopyScr()
186 {
187 return (copymap<<8)+copyscr;
188 }
189 int32_t zmap::getCopyFFC()
190 {
191 return copyffc;
192 }
193 set_ffc_command::data_t zmap::getCopyFFCData()
194 {
195 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
196 }
197 29 int32_t zmap::getMapCount()
198 {
199 29 return map_count;
200 }
201 int32_t zmap::getLayerTargetMap()
202 {
203 return layer_target_map;
204 }
205 int32_t zmap::getLayerTargetScr()
206 {
207 return layer_target_scr;
208 }
209 int32_t zmap::getLayerTargetMultiple()
210 {
211 return layer_target_multiple;
212 }
213 bool zmap::isDungeon(int32_t scr)
214 {
215 for(int32_t i=0; i<4; i++)
216 {
217 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
218 {
219 return false;
220 }
221 }
222
223 return true;
224 }
225
226 bool zmap::clearall(bool validate)
227 {
228 Color=0;
229 char tbuf[10];
230
231 if((header.templatepath[0]!=0)&&validate)
232 {
233 if(!valid_zqt(header.templatepath))
234 {
235 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
236 return false;
237 }
238 }
239
240 for(int32_t i=0; i<map_count; i++)
241 {
242 setCurrMap(i);
243 sprintf(tbuf, "%d", i);
244 clearmap(true);
245 }
246
247 setCurrMap(0);
248 return true;
249 }
250
251 bool zmap::reset_templates(bool validate)
252 {
253 //why are we doing this?
254 if(colordata==NULL)
255 {
256 return false;
257 }
258
259 //int32_t ret;
260 word version, build, dummy, sversion=0;
261 byte dummyc;
262 word dummyw;
263 //int32_t section_size;
264 word temp_map_count;
265 mapscr temp_mapscr;
266 PACKFILE *f=NULL;
267
268 // setPackfilePassword(datapwd);
269 f=open_quest_template(&header, "modules/classic/default.qst", validate);
270 get_version_and_build(f, &version, &build);
271
272 if(!find_section(f, ID_MAPS))
273 {
274 // setPackfilePassword(NULL);
275 return false;
276 }
277
278 //section version info
279 if(!p_igetw(&sversion,f))
280 {
281 return false;
282 }
283
284 if(!p_igetw(&dummy,f))
285 {
286 return false;
287 }
288
289 //section size
290 dword dummy_size;
291 if(!p_igetl(&dummy_size,f))
292 {
293 return false;
294 }
295
296 //finally... section data
297 if(!p_igetw(&temp_map_count,f))
298 {
299 return false;
300 }
301
302 if(version>12)
303 {
304 if(!p_getc(&dummyc,f))
305 return qe_invalid;
306
307 if(!p_getc(&dummyc,f))
308 return qe_invalid;
309
310 if(!p_igetw(&dummyw,f))
311 return qe_invalid;
312
313 if(!p_igetw(&dummyw,f))
314 return qe_invalid;
315
316 if(!p_igetw(&dummyw,f))
317 return qe_invalid;
318
319 if(!p_igetw(&dummyw,f))
320 return qe_invalid;
321
322 if(!p_igetw(&dummyw,f))
323 return qe_invalid;
324
325 if(!p_igetw(&dummyw,f))
326 return qe_invalid;
327
328 if(!p_igetw(&dummyw,f))
329 return qe_invalid;
330
331 if(!p_igetw(&dummyw,f))
332 return qe_invalid;
333
334 if(!p_igetw(&dummyw,f))
335 return qe_invalid;
336
337 if(!p_igetw(&dummyw,f))
338 return qe_invalid;
339
340 if(!p_getc(&dummyc,f))
341 return qe_invalid;
342
343 if(!p_getc(&dummyc,f))
344 return qe_invalid;
345 }
346
347 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
348 {
349 readmapscreen(f, &header, &temp_mapscr, sversion);
350 }
351
352 readmapscreen(f, &header, &TheMaps[128], sversion);
353 readmapscreen(f, &header, &TheMaps[129], sversion);
354
355 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
356 {
357 readmapscreen(f, &header, &temp_mapscr, sversion);
358 }
359
360 if(version>12)
361 {
362 if(!p_getc(&dummyc,f))
363 return qe_invalid;
364
365 if(!p_getc(&dummyc,f))
366 return qe_invalid;
367
368 if(!p_igetw(&dummyw,f))
369 return qe_invalid;
370
371 if(!p_igetw(&dummyw,f))
372 return qe_invalid;
373
374 if(!p_igetw(&dummyw,f))
375 return qe_invalid;
376
377 if(!p_igetw(&dummyw,f))
378 return qe_invalid;
379
380 if(!p_igetw(&dummyw,f))
381 return qe_invalid;
382
383 if(!p_igetw(&dummyw,f))
384 return qe_invalid;
385
386 if(!p_igetw(&dummyw,f))
387 return qe_invalid;
388
389 if(!p_igetw(&dummyw,f))
390 return qe_invalid;
391
392 if(!p_igetw(&dummyw,f))
393 return qe_invalid;
394
395 if(!p_igetw(&dummyw,f))
396 return qe_invalid;
397
398 if(!p_getc(&dummyc,f))
399 return qe_invalid;
400
401 if(!p_getc(&dummyc,f))
402 return qe_invalid;
403 }
404
405 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
406 {
407 readmapscreen(f, &header, &temp_mapscr, sversion);
408 }
409
410 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
411 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
412
413 pack_fclose(f);
414 clear_quest_tmpfile();
415
416 return true;
417 }
418
419 bool zmap::clearmap(bool newquest)
420 {
421 if(cursor.map<map_count)
422 {
423 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
424 {
425 clearscr(i);
426 }
427
428 setCurrScr(0);
429
430 if(newquest)
431 {
432 if(!reset_templates(false))
433 {
434 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
435 }
436 }
437 }
438
439 return true;
440 }
441
442 MapCursor zmap::getCursor() const
443 {
444 return cursor;
445 }
446
447 void zmap::setCursor(MapCursor new_cursor)
448 {
449 if (cursor == new_cursor)
450 return;
451
452 optional<int> oldcolor;
453 if (screens)
454 oldcolor = getcolor();
455
456 cursor = new_cursor;
457
458 int newcolor = getcolor();
459 loadlvlpal(newcolor);
460 if (!oldcolor || *oldcolor != newcolor)
461 rebuild_trans_table();
462
463 reset_combo_animations2();
464 mmap_mark_dirty();
465 refresh(rALL);
466 }
467
468 bool zmap::isValidPosition(ComboPosition pos) const
469 {
470 return pos.is_valid(cursor);
471 }
472
473 int zmap::getScreenForPosition(ComboPosition pos) const
474 {
475 return cursor.viewscr + pos.screen_offset();
476 }
477
478 mapscr* zmap::CurrScr()
479 {
480 return screens+cursor.screen;
481 }
482 mapscr* zmap::Scr(int32_t scr)
483 {
484 return screens+scr;
485 }
486 mapscr* zmap::Scr(ComboPosition pos)
487 {
488 if (!pos.is_valid(cursor))
489 return nullptr;
490
491 int screen_offset = pos.screen_offset();
492 int screen = cursor.viewscr + screen_offset;
493 return AbsoluteScr(cursor.map, screen);
494 }
495 mapscr* zmap::Scr(ComboPosition pos, int layer)
496 {
497 int map = cursor.map;
498 int screen = cursor.viewscr + pos.screen_offset();
499 if (layer)
500 {
501 mapscr* scr = Map.AbsoluteScr(map, screen);
502 map = scr->layermap[CurrentLayer-1]-1;
503 screen = scr->layerscreen[CurrentLayer-1];
504 }
505
506 return AbsoluteScr(map, screen);
507 }
508 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
509 {
510 mapscr* scr = Scr(pos, layer);
511 if (scr && !(scr->valid&mVALID))
512 {
513 scr->valid |= mVALID;
514 setcolor(Color, scr);
515 }
516 return scr;
517 }
518 mapscr* zmap::AbsoluteScr(int32_t scr)
519 {
520 if(unsigned(scr) >= MAPSCRS*getMapCount())
521 return nullptr;
522 return &TheMaps[scr];
523 }
524 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
525 {
526 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
527 return nullptr;
528 return AbsoluteScr((map*MAPSCRS)+scr);
529 }
530 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
531 {
532 mapscr* scr = AbsoluteScr(map, screen);
533 if (scr && !(scr->valid&mVALID))
534 {
535 scr->valid |= mVALID;
536 setcolor(Color, scr);
537 }
538 return scr;
539 }
540 void zmap::set_prvscr(int32_t map, int32_t scr)
541 {
542 prvscr=TheMaps[(map*MAPSCRS)+scr];
543
544 for(int32_t i=0; i<6; i++)
545 {
546 if(prvscr.layermap[i]>0)
547 {
548 prvlayers[i]=TheMaps[(prvscr.layermap[i]-1)*MAPSCRS+prvscr.layerscreen[i]];
549 }
550 else
551 prvlayers[i].valid = 0;
552 }
553
554 prv_map=map;
555 prv_scr=scr;
556 }
557 71 int32_t zmap::getCurrMap()
558 {
559 71 return cursor.map;
560 }
561 bool zmap::isDark(int scr)
562 {
563 return (screens[scr].flags&fDARK)!=0;
564 }
565
566 9 void zmap::setCurrMap(int32_t index)
567 {
568 9 optional<int> oldcolor;
569
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(screens)
570 oldcolor = getcolor();
571 9 scrpos[cursor.map] = cursor.screen;
572 9 scrview[cursor.map] = cursor.viewscr;
573 9 cursor.map = bound(index,0,map_count);
574 9 screens = &TheMaps[cursor.map*MAPSCRS];
575
576 9 cursor.viewscr = scrview[cursor.map];
577 9 cursor.setScreen(scrpos[cursor.map]);
578
579 9 int newcolor = getcolor();
580 9 loadlvlpal(newcolor);
581
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(!oldcolor || *oldcolor != newcolor)
582 9 rebuild_trans_table();
583
584 9 reset_combo_animations2();
585 9 mmap_mark_dirty();
586 9 }
587
588 17 int32_t zmap::getCurrScr()
589 {
590 17 return cursor.screen;
591 }
592 9 void zmap::setCurrScr(int32_t scr)
593 {
594
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if (scr == cursor.screen)
595 1 return;
596
597 8 int32_t oldcolor=getcolor();
598 8 cursor.setScreen(scr);
599
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!(screens[cursor.screen].valid&mVALID))
600 {
601 oldcolor=-1;
602 }
603
604 8 int32_t newcolor=getcolor();
605 8 loadlvlpal(newcolor);
606
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if (newcolor!=oldcolor)
607 {
608 7 rebuild_trans_table();
609 7 }
610
611 8 reset_combo_animations2();
612 8 setlayertarget();
613 8 mmap_mark_dirty();
614 9 }
615
616 int32_t zmap::getViewScr()
617 {
618 return cursor.viewscr;
619 }
620
621 9 void zmap::setViewSize(int32_t size)
622 {
623 9 cursor.setSize(size);
624 9 }
625
626 6 int32_t zmap::getViewSize()
627 {
628 6 return cursor.size;
629 }
630
631 8 void zmap::setlayertarget()
632 {
633 8 layer_target_map = 0;
634 8 layer_target_multiple = 0;
635
636
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 8 times.
29 for(int32_t m=0; m<getMapCount(); ++m)
637 {
638
2/2
✓ Branch 0 taken 2856 times.
✓ Branch 1 taken 21 times.
2877 for(int32_t s=0; s<MAPSCRS; ++s)
639 {
640 2856 int32_t i=(m*MAPSCRS+s);
641 2856 mapscr *ts=&TheMaps[i];
642
643 // Search through each layer
644
2/2
✓ Branch 0 taken 17136 times.
✓ Branch 1 taken 2856 times.
19992 for(int32_t w=0; w<6; ++w)
645 {
646
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 17134 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
17136 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
647 {
648 if(layer_target_map > 0)
649 {
650 layer_target_multiple += 1;
651 continue;
652 }
653
654 layer_target_map = m+1;
655 layer_target_scr = s;
656 }
657 17136 }
658 2856 }
659 21 }
660 8 }
661
662 void zmap::setcolor(int color, mapscr* scr)
663 {
664 if (!scr) scr = CurrScr();
665 scr->valid |= mVALID;
666 scr->color = color;
667
668 if(Color!=color)
669 {
670 Color = color;
671 loadlvlpal(color);
672 rebuild_trans_table();
673 }
674
675 mmap_mark_dirty();
676 }
677
678 25 int32_t zmap::getcolor()
679 {
680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if(prv_mode)
681 {
682 return prvscr.color;
683 }
684
685 25 return screens[cursor.screen].color;
686 25 }
687
688 void zmap::resetflags()
689 {
690 byte *di=&(screens[cursor.screen].valid);
691
692 for(int32_t i=1; i<48; i++)
693 {
694 *(di+i)=0;
695 }
696 }
697
698 word zmap::tcmbdat(int32_t pos)
699 {
700 return screens[TEMPLATE].data[pos];
701 }
702
703 word zmap::tcmbcset(int32_t pos)
704 {
705 return screens[TEMPLATE].cset[pos];
706 }
707
708 int32_t zmap::tcmbflag(int32_t pos)
709 {
710 return screens[TEMPLATE].sflag[pos];
711 }
712
713 word zmap::tcmbdat2(int32_t pos)
714 {
715 return screens[TEMPLATE2].data[pos];
716 }
717
718 word zmap::tcmbcset2(int32_t pos)
719 {
720 return screens[TEMPLATE2].cset[pos];
721 }
722
723 int32_t zmap::tcmbflag2(int32_t pos)
724 {
725 return screens[TEMPLATE2].sflag[pos];
726 }
727
728 void zmap::TemplateAll()
729 {
730 StartListCommand();
731 for(int32_t i=0; i<128; i++)
732 {
733 if((screens[i].valid&mVALID) && isDungeon(i))
734 DoTemplateCommand(-1, -1, i);
735 }
736 FinishListCommand();
737 }
738
739 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
740 {
741 if(scr==TEMPLATE)
742 return;
743
744 if(!(screens[scr].valid&mVALID))
745 screens[scr].color=Color;
746
747 screens[scr].valid|=mVALID;
748
749 for(int32_t i=0; i<32; i++)
750 {
751 screens[scr].data[i]=screens[TEMPLATE].data[i];
752 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
753 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
754 }
755
756 for(int32_t i=144; i<176; i++)
757 {
758 screens[scr].data[i]=screens[TEMPLATE].data[i];
759 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
760 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
761 }
762
763 for(int32_t y=2; y<=9; y++)
764 {
765 int32_t j=y<<4;
766 screens[scr].data[j]=screens[TEMPLATE].data[j];
767 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
768 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
769 ++j;
770 screens[scr].data[j]=screens[TEMPLATE].data[j];
771 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
772 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
773 ++j;
774 j+=12;
775 screens[scr].data[j]=screens[TEMPLATE].data[j];
776 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
777 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
778 ++j;
779 screens[scr].data[j]=screens[TEMPLATE].data[j];
780 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
781
782 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
783 ++j;
784 }
785
786 if(floorcombo!=-1)
787 {
788 for(int32_t y=2; y<9; y++)
789 for(int32_t x=2; x<14; x++)
790 {
791 int32_t i=(y<<4)+x;
792 screens[scr].data[i] = floorcombo;
793 screens[scr].cset[i] = floorcset;
794 }
795 }
796
797 for(int32_t i=0; i<4; i++)
798 putdoor(scr,i,screens[scr].door[i]);
799 }
800
801
802 void zmap::clearscr(int32_t scr)
803 {
804 screens[scr].zero_memory();
805 screens[scr].valid=mVERSION;
806 for(int q = 0; q < 6; ++q)
807 {
808 auto layer = map_autolayers[cursor.map*6+q];
809 screens[scr].layermap[q] = layer;
810 screens[scr].layerscreen[q] = layer ? scr : 0;
811 }
812 mmap_mark_dirty();
813 }
814
815 const char *loaderror[] =
816 {
817
818 "OK","File not found","Incomplete data",
819 "Invalid version","Invalid file"
820
821 };
822
823 int32_t zmap::load(const char *path)
824 {
825 PACKFILE *f=pack_fopen_password(path,F_READ, "");
826
827 if(!f)
828 return 1;
829
830
831 int16_t version;
832 byte build;
833
834 //get the version
835 if(!p_igetw(&version,f))
836 {
837 goto file_error;
838 }
839
840 //get the build
841 if(!p_getc(&build,f))
842 {
843 goto file_error;
844 }
845
846 for(int32_t i=0; i<MAPSCRS; i++)
847 {
848 mapscr tmpimportscr;
849 tmpimportscr.zero_memory();
850 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
851 {
852 al_trace("failed zmap::load\n");
853 goto file_error;
854 }
855
856 switch(ImportMapBias)
857 {
858 case 0:
859 *(screens+i) = tmpimportscr;
860 break;
861
862 case 1:
863 if(!(screens[i].valid&mVALID))
864 {
865 *(screens+i) = tmpimportscr;
866 }
867 break;
868
869 case 2:
870 if(tmpimportscr.valid&mVALID)
871 {
872 *(screens+i) = tmpimportscr;
873 }
874 break;
875 }
876 }
877
878
879 pack_fclose(f);
880
881 setCurrScr(0);
882 mmap_mark_dirty();
883 return 0;
884
885 file_error:
886 pack_fclose(f);
887 clearmap(false);
888 return 2;
889 }
890
891 int32_t zmap::save(const char *path)
892 {
893 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
894
895 if(!f)
896 return 1;
897
898 if(!p_iputw(V_MAPS,f))
899 {
900 pack_fclose(f);
901 return 3;
902 }
903
904 // This was the "build number", but that's totally useless here. Keep this junk byte
905 // so as not to totally break exports between ZC versions.
906 if(!p_putc(0,f))
907 {
908 pack_fclose(f);
909 return 3;
910 }
911
912 for(int32_t i=0; i<MAPSCRS; i++)
913 {
914 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
915 {
916 pack_fclose(f);
917 return 2;
918 }
919 }
920
921 pack_fclose(f);
922 return 0;
923 }
924
925
926 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
927 {
928 // Hookshots can be blocked by solid combos on all 3 ground layers.
929 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
930
931 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
932 return true;
933 if (c->walk&(1<<i))
934 return false;
935
936 for(int32_t k=0; k<2; k++)
937 {
938 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
939
940 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
941 {
942 return false;
943 }
944 }
945
946 return true;
947 }
948
949 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
950 {
951 // Hookshots can be blocked by solid combos on all 3 ground layers.
952 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
953
954 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
955 return true;
956 if (c->walk&(1<<i))
957 return false;
958
959 for(int32_t k=0; k<2; k++)
960 {
961 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
962
963 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
964 {
965 return false;
966 }
967 }
968
969 return true;
970 }
971
972 bool zmap::isstepable(int32_t combo)
973 {
974 // This is kind of odd but it's true to the engine (see maps.cpp)
975 return (combo_class_buf[combobuf[combo].type].ladder_pass);
976 }
977
978 // Returns the letter of the warp combo.
979 int32_t zmap::warpindex(int32_t combo)
980 {
981 switch(combobuf[combo].type)
982 {
983 case cCAVE:
984 case cPIT:
985 case cSTAIR:
986 case cCAVE2:
987 case cSWIMWARP:
988 case cDIVEWARP:
989 case cSWARPA:
990 return 0;
991
992 case cCAVEB:
993 case cPITB:
994 case cSTAIRB:
995 case cCAVE2B:
996 case cSWIMWARPB:
997 case cDIVEWARPB:
998 case cSWARPB:
999 return 1;
1000
1001 case cCAVEC:
1002 case cPITC:
1003 case cSTAIRC:
1004 case cCAVE2C:
1005 case cSWIMWARPC:
1006 case cDIVEWARPC:
1007 case cSWARPC:
1008 return 2;
1009
1010 case cCAVED:
1011 case cPITD:
1012 case cSTAIRD:
1013 case cCAVE2D:
1014 case cSWIMWARPD:
1015 case cDIVEWARPD:
1016 case cSWARPD:
1017 return 3;
1018
1019 case cPITR:
1020 case cSTAIRR:
1021 case cSWARPR:
1022 return 4;
1023 }
1024
1025 return -1;
1026
1027 }
1028
1029 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1030 {
1031 if(top)
1032 line(dest,x,y,x+15,y,c);
1033 rectfill(dest,x,y,x+3,y+15,c);
1034 rectfill(dest,x+12,y,x+15,y+15,c);
1035 rectfill(dest,x+4,y+2,x+11,y+5,c);
1036 rectfill(dest,x+4,y+10,x+11,y+13,c);
1037 }
1038
1039 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1040 {
1041 line(dest,x,y,x+15,y,c);
1042 }
1043
1044 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1045 {
1046 int32_t cx = COMBOX(pos);
1047 int32_t cy = COMBOY(pos);
1048
1049 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1050
1051 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1052
1053 int32_t bridgedetected = 0;
1054
1055 for(int32_t i=0; i<4; i++)
1056 {
1057 int32_t tx=((i&2)<<2)+x;
1058 int32_t ty=((i&1)<<3)+y;
1059 int32_t tx2=((i&2)<<2)+cx;
1060 int32_t ty2=((i&1)<<3)+cy;
1061 for (int32_t m = layer; m <= 1; m++)
1062 {
1063 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1064 {
1065 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1066 {
1067 bridgedetected |= (1<<i);
1068 }
1069 }
1070 else
1071 {
1072 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1073 {
1074 bridgedetected |= (1<<i);
1075 }
1076 }
1077 }
1078 if (bridgedetected & (1<<i))
1079 {
1080 if (i >= 3) break;
1081 else continue;
1082 }
1083 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1084 {
1085 for(int32_t k=0; k<8; k+=2)
1086 for(int32_t j=0; j<8; j+=2)
1087 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1088 }
1089 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1090 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1091
1092 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1093 {
1094 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1095 {
1096 for(int32_t k=0; k<8; k+=2)
1097 for(int32_t j=0; j<8; j+=2)
1098 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1099 }
1100 else
1101 {
1102 int32_t color = COLOR_SOLID;
1103
1104 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1105 color=vc(6);
1106 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1107 color=vc(7);
1108
1109 rectfill(dest,tx,ty,tx+7,ty+7,color);
1110 }
1111 }
1112 }
1113
1114 bridgedetected = 0;
1115 for(int32_t i=0; i<4; i++)
1116 {
1117 int32_t tx2=((i&2)<<2)+cx;
1118 int32_t ty2=((i&1)<<3)+cy;
1119 for (int32_t m = 0; m <= 1; m++)
1120 {
1121 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1122 {
1123 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1124 {
1125 bridgedetected |= (1<<i);
1126 }
1127 }
1128 else
1129 {
1130 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1131 {
1132 bridgedetected |= (1<<i);
1133 }
1134 }
1135 }
1136 }
1137
1138 // Draw damage combos
1139 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1140 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1141 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1142 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1143 || combo_class_buf[c1.type].modify_hp_amount
1144 || combo_class_buf[c2.type].modify_hp_amount;
1145
1146 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1147
1148 if(dmg)
1149 {
1150 if (bridgedetected <= 0)
1151 {
1152 for(int32_t k=0; k<16; k+=2)
1153 for(int32_t j=0; j<16; j+=2)
1154 if(((k+j)/2)%2)
1155 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1156 }
1157 else
1158 {
1159 for(int32_t i=0; i<4; i++)
1160 {
1161 if (!(bridgedetected & (1<<i)))
1162 {
1163 int32_t tx=((i&2)<<2)+x;
1164 int32_t ty=((i&1)<<3)+y;
1165 for(int32_t k=0; k<8; k+=2)
1166 for(int32_t j=0; j<8; j+=2)
1167 if(((k+j)/2)%2)
1168 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1169 }
1170 }
1171 }
1172 }
1173
1174 if(c.type == cSLOPE)
1175 {
1176 slope_info s(c, x, y);
1177 s.draw(dest, 0, 0, COLOR_SLOPE);
1178 }
1179 auto fl0 = MAPFLAG2(-1,cx,cy);
1180 auto fl1 = MAPFLAG2(0,cx,cy);
1181 auto fl2 = MAPFLAG2(1,cx,cy);
1182 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1183 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1184 {
1185 bool top = false;
1186 if(cy)
1187 {
1188 top = true;
1189 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1190 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1191 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1192 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1193 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1194 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1195 {
1196 top = false;
1197 }
1198 }
1199 draw_ladder(dest,x,y,COLOR_LADDER,top);
1200 }
1201 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1202 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1203 {
1204 draw_platform(dest,x,y,COLOR_LADDER);
1205 }
1206 }
1207
1208 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1209 {
1210 int32_t cx = COMBOX(pos);
1211 int32_t cy = COMBOY(pos);
1212
1213 if (screen < 0) return;
1214 if (map < 0) return;
1215
1216 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1217
1218 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1219
1220 int32_t bridgedetected = 0;
1221 for(int32_t i=0; i<4; i++)
1222 {
1223 int32_t tx=((i&2)<<2)+x;
1224 int32_t ty=((i&1)<<3)+y;
1225 int32_t tx2=((i&2)<<2)+cx;
1226 int32_t ty2=((i&1)<<3)+cy;
1227 for (int32_t m = layer; m <= 1; m++)
1228 {
1229 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1230 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1231 {
1232 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1233 {
1234 bridgedetected |= (1<<i);
1235 }
1236 }
1237 else
1238 {
1239 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1240 {
1241 bridgedetected |= (1<<i);
1242 }
1243 }
1244 }
1245 if (bridgedetected & (1<<i))
1246 {
1247 continue;
1248 }
1249 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1250 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1251
1252
1253 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1254 {
1255 for(int32_t k=0; k<8; k+=2)
1256 for(int32_t j=0; j<8; j+=2)
1257 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1258 }
1259 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1260 {
1261 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1262 {
1263 for(int32_t k=0; k<8; k+=2)
1264 for(int32_t j=0; j<8; j+=2)
1265 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1266 }
1267 else
1268 {
1269 int32_t color = COLOR_SOLID;
1270
1271 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1272 color=vc(6);
1273 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1274 color=vc(7);
1275
1276 rectfill(dest,tx,ty,tx+7,ty+7,color);
1277 }
1278 }
1279 }
1280
1281 bridgedetected = 0;
1282 for(int32_t i=0; i<4; i++)
1283 {
1284 int32_t tx2=((i&2)<<2)+cx;
1285 int32_t ty2=((i&1)<<3)+cy;
1286 for (int32_t m = 0; m <= 1; m++)
1287 {
1288 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1289 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1290 {
1291 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1292 {
1293 bridgedetected |= (1<<i);
1294 }
1295 }
1296 else
1297 {
1298 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1299 {
1300 bridgedetected |= (1<<i);
1301 }
1302 }
1303 }
1304 }
1305
1306 // Draw damage combos
1307 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1308 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1309 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1310 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1311 || combo_class_buf[c1.type].modify_hp_amount
1312 || combo_class_buf[c2.type].modify_hp_amount;
1313
1314 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1315
1316 if(dmg)
1317 {
1318 if (bridgedetected <= 0)
1319 {
1320 for(int32_t k=0; k<16; k+=2)
1321 for(int32_t j=0; j<16; j+=2)
1322 if(((k+j)/2)%2)
1323 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1324 }
1325 else
1326 {
1327 for(int32_t i=0; i<4; i++)
1328 {
1329 if (!(bridgedetected & (1<<i)))
1330 {
1331 int32_t tx=((i&2)<<2)+x;
1332 int32_t ty=((i&1)<<3)+y;
1333 for(int32_t k=0; k<8; k+=2)
1334 for(int32_t j=0; j<8; j+=2)
1335 if(((k+j)/2)%2)
1336 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1337 }
1338 }
1339 }
1340 }
1341
1342 if(c.type == cSLOPE)
1343 {
1344 slope_info s(c, x, y);
1345 s.draw(dest, 0, 0, COLOR_SLOPE);
1346 }
1347 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1348 auto fl1 = MAPFLAG3(map,screen,0,pos);
1349 auto fl2 = MAPFLAG3(map,screen,1,pos);
1350 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1351 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1352 {
1353 bool top = false;
1354 if(cy)
1355 {
1356 top = true;
1357 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1358 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1359 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1360 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1361 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1362 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1363 {
1364 top = false;
1365 }
1366 }
1367 draw_ladder(dest,x,y,COLOR_LADDER,top);
1368 }
1369 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1370 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1371 {
1372 draw_platform(dest,x,y,COLOR_LADDER);
1373 }
1374 }
1375
1376 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1377 {
1378 const newcombo& c = combobuf[cmbdat];
1379
1380 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1381
1382 for(int32_t i=0; i<4; i++)
1383 {
1384 int32_t tx=((i&2)<<2)+x;
1385 int32_t ty=((i&1)<<3)+y;
1386
1387 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1388 {
1389 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1390 {
1391 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1392 }
1393 else
1394 {
1395 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1396 }
1397 }
1398
1399
1400 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1401 {
1402 for(int32_t k=0; k<8; k+=2)
1403 for(int32_t j=0; j<8; j+=2)
1404 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1405 }
1406 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1407 {
1408 if(c.type==cLADDERHOOKSHOT)
1409 {
1410 for(int32_t k=0; k<8; k+=2)
1411 for(int32_t j=0; j<8; j+=2)
1412 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1413 }
1414 else
1415 {
1416 int32_t color = COLOR_SOLID;
1417
1418 if(c.type==cLADDERONLY)
1419 color=vc(6);
1420 else if(c.type==cHOOKSHOTONLY)
1421 color=vc(7);
1422
1423 rectfill(dest,tx,ty,tx+7,ty+7,color);
1424 }
1425 }
1426
1427 // Draw damage combos
1428 if(combo_class_buf[c.type].modify_hp_amount != 0)
1429 {
1430 for(int32_t k=0; k<8; k+=2)
1431 for(int32_t j=0; j<8; j+=2)
1432 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1433 }
1434 }
1435
1436 if(c.type == cSLOPE)
1437 {
1438 slope_info s(c, 0, 0);
1439 zfix const& slope = s.slope();
1440
1441 BITMAP* sub = create_bitmap_ex(8,16,16);
1442 clear_bitmap(sub);
1443 s.draw(sub, 0, 0, COLOR_SLOPE);
1444 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1445 destroy_bitmap(sub);
1446 }
1447 if(c.flag == mfSIDEVIEWLADDER)
1448 {
1449 draw_ladder(dest,x,y,COLOR_LADDER);
1450 }
1451 else if(c.flag == mfSIDEVIEWPLATFORM)
1452 {
1453 draw_platform(dest,x,y,COLOR_LADDER);
1454 }
1455 }
1456
1457 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1458 {
1459 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1460 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1461 }
1462 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1463 {
1464
1465 newcombo const& c = combobuf[cmbdat];
1466
1467 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1468 {
1469 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1470 // text_mode(-1);
1471 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1472 if(sflag)
1473 {
1474 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1475 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1476 }
1477
1478 if(c.flag)
1479 {
1480 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1481 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1482 }
1483 }
1484
1485 if(flags&cCSET)
1486 {
1487 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1488 // text_mode(inv?vc(15):vc(0));
1489 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1490 }
1491 else if(flags&cCTYPE)
1492 {
1493 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1494 // text_mode(inv?vc(15):vc(0));
1495 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1496 }
1497 }
1498
1499 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1500 {
1501 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1502
1503 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1504 if(repos)
1505 {
1506 combotile_override_x = x+(8*(scale-1));
1507 combotile_override_y = y+(8*(scale-1));
1508 }
1509 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1510 if(repos) combotile_override_x = combotile_override_y = -1;
1511 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1512 destroy_bitmap(b);
1513 }
1514 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1515 {
1516 static newcombo nilcombo;
1517 nilcombo.tile = 0;
1518
1519 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1520
1521 if(c.tile==0)
1522 {
1523 rectfill(dest,x,y,x+15,y+15,vc(0));
1524 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1525 return;
1526 }
1527
1528 putcombo(dest,x,y,cmbdat,cset);
1529
1530 /* moved to put_walkflags
1531 for(int32_t i=0; i<4; i++) {
1532
1533 int32_t tx=((i&2)<<2)+x;
1534 int32_t ty=((i&1)<<3)+y;
1535 if((flags&cWALK) && (c.walk&(1<<i)))
1536 rectfill(dest,tx,ty,tx+7,ty+7,COLOR_SOLID);
1537 }
1538 */
1539
1540 // if((flags&cFLAGS)&&(cmbdat&0xF800))
1541 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1542 {
1543 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1544 // text_mode(-1);
1545 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1546 if(sflag)
1547 {
1548 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1549 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1550 }
1551
1552 if(combobuf[cmbdat].flag)
1553 {
1554 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1555 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1556 }
1557 }
1558
1559 if(flags&cWALK)
1560 {
1561 put_walkflags(dest,x,y,cmbdat,0);
1562 }
1563
1564 if(flags&cCSET)
1565 {
1566 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1567 // text_mode(inv?vc(15):vc(0));
1568 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1569 }
1570 else if(flags&cCTYPE)
1571 {
1572 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1573 // text_mode(inv?vc(15):vc(0));
1574 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1575 }
1576 }
1577 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1578 {
1579 auto blitx = 1 + (slot % 16) * 17;
1580 auto blity = 1 + (slot / 16) * 17;
1581 masked_stretch_blit((BITMAP*)zcdata[BMP_ENGRAVINGS].dat, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1582 }
1583
1584
1585 void copy_mapscr(mapscr *dest, const mapscr *src)
1586 {
1587 if(!dest || !src) return;
1588 *dest = *src;
1589 }
1590
1591 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1592 {
1593 int32_t x=0,y=0;
1594 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1595
1596 switch(side)
1597 {
1598 case up:
1599 case down:
1600 x=((pos&15)<<4)+xofs;
1601 y=(ignorepos?0:(pos&0xF0))+yofs;
1602 break;
1603
1604 case left:
1605 case right:
1606 x=(ignorepos?0:((pos&15)<<4))+xofs;
1607 y=(pos&0xF0)+yofs;
1608 break;
1609 }
1610
1611 switch(type)
1612 {
1613 case dt_lock:
1614 case dt_shut:
1615 case dt_boss:
1616 case dt_bomb:
1617 switch(side)
1618 {
1619 case up:
1620 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1621 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1622 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1623 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1624 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1625 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1626 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1627 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1628 break;
1629
1630 case down:
1631 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1632 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1633 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1634 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1635 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1636 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1637 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1638 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1639 break;
1640
1641 case left:
1642 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1643 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1644 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1645 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1646 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1647 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1648
1649 if(x+16 >= dest->w)
1650 break;
1651
1652 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1653 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1654 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1655 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1656 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1657 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1658 break;
1659
1660 case right:
1661
1662 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1663 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1664 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1665 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1666 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1667 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1668
1669 if(x+16 <= 0)
1670 break;
1671
1672 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1673 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1674 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1675 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1676 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1677 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1678 break;
1679 }
1680
1681 break;
1682
1683 case dt_pass:
1684 case dt_wall:
1685 case dt_walk:
1686 default:
1687 break;
1688 }
1689 }
1690
1691 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1692 {
1693 int32_t x=((pos&15)<<4)+xofs;
1694 int32_t y=(pos&0xF0)+yofs;
1695 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1696
1697
1698 switch(side)
1699 {
1700 case up:
1701 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1702 {
1703 overcombo(dest,x,y,
1704 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1705 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1706 }
1707
1708 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1709 {
1710 overcombo(dest,x+16,y,
1711 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1712
1713 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1714 }
1715
1716 break;
1717
1718 case down:
1719 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1720 {
1721 overcombo(dest,x,y,
1722 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1723 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1724 }
1725
1726 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1727 {
1728 overcombo(dest,x+16,y,
1729 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1730 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1731 }
1732
1733 break;
1734
1735 case left:
1736 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1737 {
1738 overcombo(dest,x,y,
1739 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1740 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1741 }
1742
1743 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1744 {
1745 overcombo(dest,x,y+16,
1746 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1747 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1748 }
1749
1750 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1751 {
1752 overcombo(dest,x,y+32,
1753 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1754 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1755 }
1756
1757 break;
1758
1759 case right:
1760 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1761 {
1762 overcombo(dest,x,y,
1763 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1764 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1765 }
1766
1767 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1768 {
1769 overcombo(dest,x,y+16,
1770
1771 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1772 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1773 }
1774
1775 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1776 {
1777 overcombo(dest,x,y+32,
1778 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1779 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1780 }
1781
1782 break;
1783 }
1784 }
1785
1786 bool zmap::misaligned(int32_t map, int32_t scr, int32_t i, int32_t dir)
1787 {
1788 word cmbcheck1, cmbcheck2;
1789 newcombo combocheck1, combocheck2;
1790 combocheck1 = combobuf[0];
1791 combocheck2 = combobuf[0];
1792 combocheck1.walk = 0;
1793 combocheck2.walk = 0;
1794
1795 int32_t layermap, layerscreen;
1796
1797 switch(dir)
1798 {
1799 case up:
1800 {
1801 if(i>15) //not top row of combos
1802 {
1803 return false;
1804 }
1805
1806 if(scr<16) //top row of screens
1807 {
1808 return false;
1809
1810 }
1811
1812 //check main screen
1813 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1814 cmbcheck2 = vbound(AbsoluteScr(map, scr-16)->data[i+160], 0, MAXCOMBOS-1);
1815 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1816 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1817
1818 //check layer 1
1819 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1820
1821 if(layermap>-1 && layermap<map_count)
1822 {
1823 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1824 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1825 if (combobuf[cmbcheck1].type == cBRIDGE)
1826 {
1827 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1828 {
1829 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1830 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1831 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1832 }
1833 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1834 }
1835 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1836 }
1837
1838 layermap=AbsoluteScr(map, scr-16)->layermap[0]-1;
1839
1840 if(layermap>-1 && layermap<map_count)
1841 {
1842 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[0];
1843 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1844 if (combobuf[cmbcheck2].type == cBRIDGE)
1845 {
1846 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1847 {
1848 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1849 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1850 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1851 }
1852 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1853 }
1854 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1855 }
1856
1857 //check layer 2
1858 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1859
1860 if(layermap>-1 && layermap<map_count)
1861 {
1862 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1863
1864 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1865 if (combobuf[cmbcheck2].type == cBRIDGE)
1866 {
1867 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1868 {
1869 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1870 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1871 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1872 }
1873 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1874 }
1875 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1876 }
1877
1878 layermap=AbsoluteScr(map, scr-16)->layermap[1]-1;
1879
1880 if(layermap>-1 && layermap<map_count)
1881 {
1882 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[1];
1883 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1884 if (combobuf[cmbcheck2].type == cBRIDGE)
1885 {
1886 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1887 {
1888 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1889 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1890 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1891 }
1892 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1893 }
1894 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1895 }
1896
1897 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1898 {
1899 return true;
1900 }
1901
1902 break;
1903 }
1904 case down:
1905 {
1906 if(i<160) //not bottom row of combos
1907 {
1908 return false;
1909 }
1910
1911 if(scr>111) //bottom row of screens
1912 {
1913 return false;
1914 }
1915
1916 //check main screen
1917 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1918 cmbcheck2 = vbound(AbsoluteScr(map, scr+16)->data[i-160], 0, MAXCOMBOS-1);
1919 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1920 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1921
1922
1923 //check layer 1
1924 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1925
1926 if(layermap>-1 && layermap<map_count)
1927 {
1928 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1929 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1930 if (combobuf[cmbcheck1].type == cBRIDGE)
1931 {
1932 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1933 {
1934 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1935 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1936 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1937 }
1938 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1939 }
1940 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1941 }
1942
1943 layermap=AbsoluteScr(map, scr+16)->layermap[0]-1;
1944
1945 if(layermap>-1 && layermap<map_count)
1946 {
1947 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[0];
1948 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1949 if (combobuf[cmbcheck2].type == cBRIDGE)
1950 {
1951 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1952 {
1953 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1954 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1955 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1956 }
1957 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1958 }
1959 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1960 }
1961
1962 //check layer 2
1963 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1964
1965 if(layermap>-1 && layermap<map_count)
1966 {
1967 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1968 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1969 if (combobuf[cmbcheck1].type == cBRIDGE)
1970 {
1971 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1972 {
1973 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1974 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1975 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1976 }
1977 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1978 }
1979 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1980 }
1981
1982 layermap=AbsoluteScr(map, scr+16)->layermap[1]-1;
1983
1984 if(layermap>-1 && layermap<map_count)
1985 {
1986 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[1];
1987 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1988 if (combobuf[cmbcheck2].type == cBRIDGE)
1989 {
1990 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1991 {
1992 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1993 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1994 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1995 }
1996 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1997 }
1998 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1999 }
2000
2001 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2002 {
2003 return true;
2004 }
2005
2006 break;
2007 }
2008 case left:
2009 {
2010 if((i&0xF)!=0) //not left column of combos
2011 {
2012 return false;
2013 }
2014
2015 if((scr&0xF)==0) //left column of screens
2016 {
2017 return false;
2018 }
2019
2020 //check main screen
2021 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
2022 cmbcheck2 = AbsoluteScr(map, scr-1)->data[i+15];
2023 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2024 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2025
2026 //check layer 1
2027 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
2028
2029 if(layermap>-1 && layermap<map_count)
2030 {
2031 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
2032 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2033 if (combobuf[cmbcheck1].type == cBRIDGE)
2034 {
2035 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2036 {
2037 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2038 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2039 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2040 }
2041 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2042 }
2043 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2044 }
2045
2046 layermap=AbsoluteScr(map, scr-1)->layermap[0]-1;
2047
2048 if(layermap>-1 && layermap<map_count)
2049 {
2050 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[0];
2051 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2052 if (combobuf[cmbcheck2].type == cBRIDGE)
2053 {
2054 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2055 {
2056 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2057 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2058 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2059 }
2060 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2061 }
2062 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2063 }
2064
2065 //check layer 2
2066 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2067
2068 if(layermap>-1 && layermap<map_count)
2069 {
2070 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2071 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2072 if (combobuf[cmbcheck1].type == cBRIDGE)
2073 {
2074 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2075 {
2076 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2077 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2078 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2079 }
2080 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2081 }
2082 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2083 }
2084
2085 layermap=AbsoluteScr(map, scr-1)->layermap[1]-1;
2086
2087 if(layermap>-1 && layermap<map_count)
2088 {
2089 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[1];
2090 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2091 if (combobuf[cmbcheck2].type == cBRIDGE)
2092 {
2093 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2094 {
2095 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2096 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2097 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2098 }
2099 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2100 }
2101 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2102 }
2103
2104 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2105 {
2106 return true;
2107 }
2108
2109 break;
2110 }
2111 case right:
2112 {
2113 if((i&0xF)!=15) //not right column of combos
2114 {
2115 return false;
2116 }
2117
2118 if((scr&0xF)==15) //right column of screens
2119 {
2120 return false;
2121 }
2122
2123 //check main screen
2124 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
2125 cmbcheck2 = AbsoluteScr(map, scr+1)->data[i-15];
2126 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2127 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2128
2129 //check layer 1
2130 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
2131
2132 if(layermap>-1 && layermap<map_count)
2133 {
2134 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
2135 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2136 if (combobuf[cmbcheck1].type == cBRIDGE)
2137 {
2138 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2139 {
2140 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2141 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2142 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2143 }
2144 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2145 }
2146 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2147 }
2148
2149 layermap=AbsoluteScr(map, scr+1)->layermap[0]-1;
2150
2151 if(layermap>-1 && layermap<map_count)
2152 {
2153 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[0];
2154 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2155 if (combobuf[cmbcheck2].type == cBRIDGE)
2156 {
2157 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2158 {
2159 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2160 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2161 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2162 }
2163 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2164 }
2165 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2166 }
2167
2168 //check layer 2
2169 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2170
2171 if(layermap>-1 && layermap<map_count)
2172 {
2173 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2174 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2175 if (combobuf[cmbcheck1].type == cBRIDGE)
2176 {
2177 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2178 {
2179 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2180 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2181 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2182 }
2183 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2184 }
2185 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2186 }
2187
2188 layermap=AbsoluteScr(map, scr+1)->layermap[1]-1;
2189
2190 if(layermap>-1 && layermap<map_count)
2191 {
2192 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[1];
2193
2194 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2195 if (combobuf[cmbcheck2].type == cBRIDGE)
2196 {
2197 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2198 {
2199 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2200 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2201 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2202 }
2203 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2204 }
2205 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2206 }
2207
2208 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2209 {
2210 return true;
2211 }
2212
2213 break;
2214 }
2215 }
2216
2217 return false;
2218 }
2219
2220 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2221 {
2222 int32_t checkcombo;
2223
2224 if(alignment_arrow_timer>31)
2225 {
2226 if(scr<0)
2227 {
2228 scr=cursor.screen;
2229 }
2230
2231 if((scr<128)) //do the misalignment arrows
2232 {
2233 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2234 {
2235 if(misaligned(cursor.map, scr, checkcombo, up))
2236 {
2237 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2238 }
2239 }
2240
2241 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2242 {
2243 if(misaligned(cursor.map, scr, checkcombo, down))
2244 {
2245 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2246 }
2247 }
2248
2249 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2250 {
2251 if(misaligned(cursor.map, scr, checkcombo, left))
2252 {
2253 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2254 }
2255 }
2256
2257 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2258 {
2259 if(misaligned(cursor.map, scr, checkcombo, right))
2260 {
2261 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2262 }
2263 }
2264
2265 int32_t tempalign;
2266
2267 //check top left corner
2268 checkcombo=0;
2269 tempalign=0;
2270 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2271 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2272
2273 switch(tempalign)
2274 {
2275 case 0:
2276 break;
2277
2278 case 1: //up
2279 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2280 break;
2281
2282 case 2: //left
2283 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2284 break;
2285
2286 case 3: //up-left
2287 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2288 break;
2289 }
2290
2291 //check top right corner
2292 checkcombo=15;
2293 tempalign=0;
2294 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2295 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2296
2297 switch(tempalign)
2298 {
2299 case 0:
2300 break;
2301
2302 case 1: //up
2303 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2304 break;
2305
2306 case 2: //right
2307 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2308 break;
2309
2310 case 3: //up-right
2311 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2312 break;
2313 }
2314
2315 //check bottom left corner
2316 checkcombo=160;
2317 tempalign=0;
2318 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2319 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2320
2321 switch(tempalign)
2322 {
2323 case 0:
2324 break;
2325
2326 case 1: //down
2327 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2328 break;
2329
2330 case 2: //left
2331 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2332 break;
2333
2334 case 3: //down-left
2335 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2336 break;
2337 }
2338
2339 //check bottom right corner
2340
2341 checkcombo=175;
2342 tempalign=0;
2343 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2344 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2345
2346 switch(tempalign)
2347 {
2348 case 0:
2349 break;
2350
2351 case 1: //down
2352 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2353 break;
2354
2355 case 2: //right
2356 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2357 break;
2358
2359 case 3: //down-right
2360 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2361 break;
2362 }
2363 }
2364 }
2365 }
2366
2367 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2368 {
2369 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2370 }
2371
2372 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2373 {
2374 if (map < 0 || screen < 0) return 0;
2375
2376 if(pos>175 || pos < 0)
2377 return 0;
2378
2379 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2380
2381 if(m->valid==0) return 0;
2382
2383 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2384
2385 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2386
2387 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2388
2389 if(scr->valid==0) return 0;
2390
2391 return scr->data[pos]; // entire combo code
2392 }
2393
2394 // Takes array index layer num., not actual layer num.
2395 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2396 {
2397 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2398
2399 if(map<0)
2400 map=cursor.map;
2401
2402 if(scr<0)
2403 scr=cursor.screen;
2404
2405 mapscr *screen1;
2406
2407 if(prv_mode)
2408 {
2409 screen1=get_prvscr();
2410 }
2411 else
2412 {
2413 screen1=AbsoluteScr(cursor.map,cursor.screen);
2414 }
2415
2416 int32_t layermap;
2417 layermap=screen1->layermap[lyr]-1;
2418
2419 if(layermap<0 || layermap >= map_count) return 0;
2420
2421 mapscr *layer;
2422
2423 if(prv_mode)
2424 layer = &prvlayers[lyr];
2425 else
2426 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2427
2428 int32_t combo = COMBOPOS(x,y);
2429
2430 if(combo>175 || combo < 0)
2431 return 0;
2432
2433 return layer->data[combo];
2434 }
2435
2436 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2437 {
2438 if(map<0)
2439 map=cursor.map;
2440
2441 if(scr<0)
2442 scr=cursor.screen;
2443
2444 mapscr *screen1;
2445
2446 if(prv_mode)
2447 {
2448 screen1=get_prvscr();
2449 }
2450 else
2451 {
2452 screen1=AbsoluteScr(cursor.map,cursor.screen);
2453 }
2454
2455 x = vbound(x, 0, 16*16);
2456 y = vbound(y, 0, 11*16);
2457 int32_t combo = COMBOPOS(x,y);
2458
2459 if(combo>175 || combo < 0)
2460 return 0;
2461
2462 return screen1->data[combo];
2463 }
2464
2465 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2466 {
2467 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2468 }
2469
2470 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2471 {
2472 if (map < 0 || screen < 0) return 0;
2473
2474 if(pos>175 || pos < 0)
2475 return 0;
2476
2477 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2478
2479 if(m->valid==0) return 0;
2480
2481 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2482
2483 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2484
2485 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2486
2487 if(scr->valid==0) return 0;
2488
2489 return scr->sflag[pos]; // entire combo code
2490 }
2491
2492 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2493 {
2494 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2495
2496 if(map<0)
2497 map=cursor.map;
2498
2499 if(scr<0)
2500 scr=cursor.screen;
2501
2502 mapscr *screen1;
2503
2504 if(prv_mode)
2505 {
2506 screen1=get_prvscr();
2507 }
2508 else
2509 {
2510 screen1=AbsoluteScr(cursor.map,cursor.screen);
2511 }
2512
2513 int32_t layermap;
2514 layermap=screen1->layermap[lyr]-1;
2515
2516 if(layermap<0 || layermap >= map_count) return 0;
2517
2518 mapscr *layer;
2519
2520 if(prv_mode)
2521 layer = &prvlayers[lyr];
2522 else
2523 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2524
2525 int32_t combo = COMBOPOS(x,y);
2526
2527 if(combo>175 || combo < 0)
2528 return 0;
2529
2530 return layer->sflag[combo];
2531 }
2532
2533 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2534 {
2535 if(map<0)
2536 map=cursor.map;
2537
2538 if(scr<0)
2539 scr=cursor.screen;
2540
2541 mapscr *screen1;
2542
2543 if(prv_mode)
2544 {
2545 screen1=get_prvscr();
2546 }
2547 else
2548 {
2549 screen1=AbsoluteScr(cursor.map,cursor.screen);
2550 }
2551
2552 x = vbound(x, 0, 16*16);
2553 y = vbound(y, 0, 11*16);
2554 int32_t combo = COMBOPOS(x,y);
2555
2556 if(combo>175 || combo < 0)
2557 return 0;
2558
2559 return screen1->sflag[combo];
2560 }
2561
2562 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2563 {
2564 mapscr *layers[7];
2565 mapscr *basescr;
2566 if(prv_mode)
2567 {
2568 layers[0] = &prvscr;
2569 basescr = layers[0];
2570 for(auto q = 1; q < 7; ++q)
2571 {
2572 if(prvlayers[q-1].valid)
2573 layers[q] = &(prvlayers[q-1]);
2574 else layers[q] = NULL;
2575 }
2576 }
2577 else
2578 {
2579 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2580 basescr = layers[0];
2581 for(auto q = 1; q < 7; ++q)
2582 {
2583 int32_t lmap = basescr->layermap[q-1]-1;
2584 int32_t lscr = basescr->layerscreen[q-1];
2585 if(lmap < 0)
2586 layers[q] = NULL;
2587 else layers[q] = AbsoluteScr(lmap, lscr);
2588 }
2589 }
2590 for(auto q = 0; q < 7; ++q)
2591 {
2592 if(!layers[q]) continue;
2593 for(auto pos = 0; pos < 176; ++pos)
2594 {
2595 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2596 if(cmb.type == cTORCH)
2597 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2598 }
2599 }
2600 word maxffc = basescr->numFFC();
2601 for(auto q = 0; q < maxffc; ++q)
2602 {
2603 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2604 if(cmb.type == cTORCH)
2605 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2606 }
2607 }
2608
2609 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2610 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2611 {
2612 newcombo const& cmb = combobuf[cid];
2613 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2614 if(dither)
2615 {
2616 if (LayerDitherSz == 0)
2617 return;
2618 BITMAP* buf = create_bitmap_ex(8,16,16);
2619 clear_bitmap(buf);
2620 overcombo(buf,0,0,cid,cset);
2621 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2622 if(over)
2623 {
2624 if(transp)
2625 {
2626 color_map = &trans_table2;
2627 draw_trans_sprite(dest, buf, x, y);
2628 color_map = &trans_table;
2629 }
2630 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2631 }
2632 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2633 destroy_bitmap(buf);
2634 }
2635 else if(over)
2636 {
2637 if(transp)
2638 overcombotranslucent(dest,x,y,cid,cset,0);
2639 else overcombo(dest,x,y,cid,cset);
2640 }
2641 else put_combo(dest,x,y,cid,cset,flags,sflag);
2642 }
2643 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2644 {
2645 if(!md) return;
2646 for (int32_t i = 0; i < 176; i++)
2647 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2648 }
2649 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2650 {
2651 if(!md) return;
2652 for (int32_t i = 0; i < 176; i++)
2653 {
2654 int data = md->data[i];
2655 if(combo_class_buf[combobuf[data].type].overhead)
2656 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2657 }
2658 }
2659 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2660 {
2661 if(!LayerMaskInt[lyr])
2662 return nullptr;
2663 if(lyr == 0)
2664 return basescr;
2665 int layermap = basescr->layermap[lyr-1]-1;
2666
2667 if(layermap>-1 && layermap<map_count)
2668 {
2669 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2670 return &TheMaps[layerscreen];
2671 }
2672 return nullptr;
2673 }
2674 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t scr,int32_t hl_layer)
2675 {
2676 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2677 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2678
2679 if(map<0)
2680 map=cursor.map;
2681
2682 if(scr<0)
2683 scr=cursor.screen;
2684
2685 mapscr *basescr;
2686 mapscr* layers[7] = {nullptr};
2687
2688 if(prv_mode)
2689 {
2690 hl_layer = -1;
2691 basescr=get_prvscr();
2692 }
2693 else
2694 {
2695 basescr=AbsoluteScr(map,scr);
2696 }
2697 layers[0] = _zmap_get_lyr_checked(0,basescr);
2698 for(int lyr = 1; lyr < 7; ++lyr)
2699 {
2700 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2701 : _zmap_get_lyr_checked(lyr,basescr);
2702 }
2703
2704 int32_t layermap, layerscreen;
2705 if(CurrentLayer < 1)
2706 layermap = -1;
2707 else
2708 {
2709 layermap=basescr->layermap[CurrentLayer-1]-1;
2710
2711 if(layermap<0)
2712 CurrentLayer=0;
2713 }
2714
2715 if(!(basescr->valid&mVALID))
2716 {
2717 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2718 rectfill(dest,x,y,x+255,y+175,vc(1));
2719
2720 if(ShowMisalignments)
2721 {
2722 check_alignments(dest,x,y,scr);
2723 }
2724
2725 return;
2726 }
2727
2728 if(LayerMaskInt[0]==0)
2729 {
2730 byte bgfill = 0;
2731 if (LayerDitherBG > -1)
2732 bgfill = vc(LayerDitherBG);
2733 rectfill(dest,x,y,x+255,y+175,bgfill);
2734 }
2735
2736 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2737 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2738
2739 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2740 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2741
2742 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2743
2744 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2745
2746 int num_ffcs = basescr->numFFC();
2747 for(int32_t i=num_ffcs-1; i>=0; i--)
2748 {
2749 if(basescr->ffcs[i].data)
2750 {
2751 if(!(basescr->ffcs[i].flags&ffc_changer))
2752 {
2753 if(!(basescr->ffcs[i].flags&ffc_overlay))
2754 {
2755 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2756 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2757
2758 if(basescr->ffcs[i].flags&ffc_trans)
2759 {
2760 overcomboblocktranslucent(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset,basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2761 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2762 }
2763 else
2764 {
2765 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2766 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2767 }
2768 }
2769 }
2770 }
2771 }
2772
2773 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2774 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2775
2776 int32_t doortype[4];
2777
2778 for(int32_t i=0; i<4; i++)
2779 {
2780 switch(basescr->door[i])
2781 {
2782 case dOPEN:
2783 doortype[i]=dt_pass;
2784 break;
2785
2786 case dLOCKED:
2787 doortype[i]=dt_lock;
2788 break;
2789
2790 case d1WAYSHUTTER:
2791 case dSHUTTER:
2792 doortype[i]=dt_shut;
2793 break;
2794
2795 case dBOSS:
2796 doortype[i]=dt_boss;
2797 break;
2798
2799 case dBOMB:
2800 doortype[i]=dt_bomb;
2801 break;
2802 }
2803 }
2804
2805 switch(basescr->door[up])
2806 {
2807 case dBOMB:
2808 over_door(dest,39,up,x,y,false, scr);
2809 [[fallthrough]];
2810 case dOPEN:
2811 case dLOCKED:
2812 case d1WAYSHUTTER:
2813 case dSHUTTER:
2814 case dBOSS:
2815 put_door(dest,7,up,doortype[up],x,y,false,scr);
2816 break;
2817
2818 case dWALK:
2819 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2820 {
2821 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2822 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2823 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0]);
2824 }
2825 else
2826
2827 {
2828 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2829 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2830 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0],0,0);
2831 }
2832
2833 break;
2834 }
2835
2836 switch(basescr->door[down])
2837 {
2838 case dBOMB:
2839 over_door(dest,135,down,x,y,false,scr);
2840 [[fallthrough]];
2841 case dOPEN:
2842 case dLOCKED:
2843 case d1WAYSHUTTER:
2844 case dSHUTTER:
2845 case dBOSS:
2846 put_door(dest,151,down,doortype[down],x,y,false,scr);
2847 break;
2848
2849 case dWALK:
2850 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2851 {
2852 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2853 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2854 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1]);
2855 }
2856 else
2857 {
2858 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2859 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2860 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1],0,0);
2861 }
2862
2863 break;
2864 }
2865
2866 switch(basescr->door[left])
2867 {
2868 case dBOMB:
2869 over_door(dest,66,left,x,y,false,scr);
2870 [[fallthrough]];
2871 case dOPEN:
2872 case dLOCKED:
2873 case d1WAYSHUTTER:
2874 case dSHUTTER:
2875 case dBOSS:
2876 put_door(dest,64,left,doortype[left],x,y,false,scr);
2877 break;
2878
2879 case dWALK:
2880 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2881 {
2882 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2883 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2884 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2]);
2885 }
2886 else
2887 {
2888 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2889 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2890 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2],0,0);
2891 }
2892
2893 break;
2894 }
2895
2896 switch(basescr->door[right])
2897 {
2898
2899 case dBOMB:
2900 over_door(dest,77,right,x,y,false,scr);
2901 [[fallthrough]];
2902 case dOPEN:
2903 case dLOCKED:
2904 case d1WAYSHUTTER:
2905 case dSHUTTER:
2906 case dBOSS:
2907 put_door(dest,78,right,doortype[right],x,y,false,scr);
2908 break;
2909
2910 case dWALK:
2911 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2912 {
2913 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2914 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2915 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3]);
2916 }
2917 else
2918 {
2919 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2920 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2921 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3],0,0);
2922 }
2923
2924 break;
2925 }
2926
2927 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2928 {
2929 frame=0;
2930 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2931 }
2932
2933 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2934 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2935 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2936
2937 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2938
2939 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2940 {
2941 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2942 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2943 }
2944 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2945
2946 for(int32_t i=num_ffcs-1; i>=0; i--)
2947 {
2948 if(basescr->ffcs[i].data)
2949 {
2950 if(!(basescr->ffcs[i].flags&ffc_changer))
2951 {
2952 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2953 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2954
2955 if(basescr->ffcs[i].flags&ffc_overlay)
2956 {
2957 if(basescr->ffcs[i].flags&ffc_trans)
2958 {
2959 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2960 overcomboblocktranslucent(dest,tx,ty,basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2961 }
2962 else
2963 {
2964 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2965 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2966 }
2967 }
2968 }
2969 }
2970 }
2971
2972 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2973
2974 for(int32_t i=num_ffcs-1; i>=0; i--)
2975 if(basescr->ffcs[i].data)
2976 if(basescr->ffcs[i].flags&ffc_changer)
2977 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2978
2979 if(flags&cWALK)
2980 {
2981 if(layers[0])
2982 for(int32_t i=0; i<176; i++)
2983 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2984
2985 for(int32_t k=0; k<2; k++)
2986 {
2987 if(layers[k+1])
2988 for(int32_t i=0; i<176; i++)
2989 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2990 }
2991 for(int32_t i=num_ffcs-1; i>=0; i--)
2992 {
2993 if(auto data = basescr->ffcs[i].data)
2994 {
2995 if(!(basescr->ffcs[i].flags&ffc_changer))
2996 {
2997 newcombo const& cmb = combobuf[data];
2998 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2999 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
3000
3001 if(basescr->ffcs[i].flags&ffc_solid)
3002 {
3003 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
3004 }
3005
3006 if(cmb.type == cSLOPE)
3007 {
3008 slope_info s(cmb, tx, ty);
3009 s.draw(dest, 0, 0, COLOR_SLOPE);
3010 }
3011 }
3012 }
3013 }
3014 }
3015
3016 if(flags&cFLAGS)
3017 {
3018 if(LayerMaskInt[CurrentLayer]!=0)
3019 {
3020 for(int32_t i=0; i<176; i++)
3021 {
3022 if(CurrentLayer==0)
3023 {
3024 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
3025 }
3026 else
3027 {
3028 if(prv_mode)
3029 {
3030 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
3031 }
3032 else
3033 {
3034 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
3035
3036 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3037 {
3038 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
3039 TheMaps[_lscr].data[i],
3040 TheMaps[_lscr].cset[i], flags,
3041 TheMaps[_lscr].sflag[i]);
3042 }
3043 }
3044 }
3045 }
3046 }
3047 }
3048
3049 int32_t dark = basescr->flags&cDARK;
3050
3051 if(dark && !(flags&cNODARK)
3052 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
3053 {
3054 for(int32_t j=0; j<80; j++)
3055 {
3056 for(int32_t i=0; i<(80)-j; i++)
3057 {
3058 if(((i^j)&1)==0)
3059 {
3060 putpixel(dest,x+i,y+j,vc(blackout_color));
3061 }
3062 }
3063 }
3064 }
3065
3066 if(ShowMisalignments)
3067 {
3068 check_alignments(dest,x,y,scr);
3069 }
3070 }
3071
3072 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3073 {
3074 if(map<0)
3075 map=cursor.map;
3076
3077 if(scr<0)
3078 scr=cursor.screen;
3079
3080 mapscr* layer=AbsoluteScr(map,scr);
3081 int32_t layermap=0, layerscreen=0;
3082
3083 if(!(layer->valid&mVALID))
3084 {
3085 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3086 rectfill(dest,x,y,x+255,y+15,vc(1));
3087 return;
3088 }
3089
3090 int32_t dark = layer->flags&4;
3091
3092 if(LayerMaskInt[0]==0)
3093 {
3094 rectfill(dest,x,y,x+255,y+15,0);
3095 }
3096
3097
3098 for(int32_t k=1; k<3; k++)
3099 {
3100 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3101 {
3102 layermap=layer->layermap[k]-1;
3103
3104 if(layermap>-1 && layermap<map_count)
3105 {
3106 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3107
3108 for(int32_t i=c; i<(c&0xF0)+16; i++)
3109 {
3110 auto data = TheMaps[layerscreen].data[i];
3111 auto cs = TheMaps[layerscreen].cset[i];
3112 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3113 }
3114 }
3115 }
3116 }
3117
3118 if(LayerMaskInt[0]!=0)
3119 {
3120 for(int32_t i=c; i<(c&0xF0)+16; i++)
3121 {
3122 word cmbdat = (i < 176 ? layer->data[i] : 0);
3123 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3124 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3125 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3126 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3127 }
3128 }
3129
3130 for(int32_t k=0; k<2; k++)
3131 {
3132 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3133 {
3134 layermap=layer->layermap[k]-1;
3135
3136 if(layermap>-1 && layermap<map_count)
3137 {
3138 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3139
3140 for(int32_t i=c; i<(c&0xF0)+16; i++)
3141 {
3142 auto data = TheMaps[layerscreen].data[i];
3143 auto cs = TheMaps[layerscreen].cset[i];
3144 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3145 }
3146 }
3147 }
3148 }
3149
3150 int32_t doortype[4];
3151
3152 for(int32_t i=0; i<4; i++)
3153 {
3154 switch(layer->door[i])
3155 {
3156 case dOPEN:
3157 doortype[i]=dt_pass;
3158 break;
3159
3160 case dLOCKED:
3161 doortype[i]=dt_lock;
3162 break;
3163
3164 case d1WAYSHUTTER:
3165 case dSHUTTER:
3166 doortype[i]=dt_shut;
3167 break;
3168
3169 case dBOSS:
3170 doortype[i]=dt_boss;
3171 break;
3172
3173 case dBOMB:
3174 doortype[i]=dt_bomb;
3175 break;
3176 }
3177 }
3178
3179 if(c<16)
3180 {
3181 switch(layer->door[up])
3182 {
3183 case dBOMB:
3184 case dOPEN:
3185 case dLOCKED:
3186 case d1WAYSHUTTER:
3187 case dSHUTTER:
3188 case dBOSS:
3189 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3190 break;
3191 }
3192 }
3193 else if(c>159)
3194 {
3195 switch(layer->door[down])
3196 {
3197 case dBOMB:
3198 case dOPEN:
3199 case dLOCKED:
3200 case d1WAYSHUTTER:
3201 case dSHUTTER:
3202 case dBOSS:
3203 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3204 break;
3205 }
3206 }
3207
3208 for(int32_t k=2; k<4; k++)
3209 {
3210 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3211 {
3212 layermap=layer->layermap[k]-1;
3213
3214 if(layermap>-1 && layermap<map_count)
3215 {
3216 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3217
3218 for(int32_t i=c; i<(c&0xF0)+16; i++)
3219 {
3220 if(layer->layeropacity[k]<255)
3221 {
3222 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3223 }
3224 else
3225 {
3226 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3227 }
3228 }
3229 }
3230 }
3231 }
3232
3233 //Overhead L0
3234 if(LayerMaskInt[0]!=0)
3235 {
3236 for(int32_t i=c; i<(c&0xF0)+16; i++)
3237 {
3238 int32_t ct1=layer->data[i];
3239 int32_t ct3=combobuf[ct1].type;
3240
3241 if(combo_class_buf[ct3].overhead)
3242 {
3243 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3244 }
3245 }
3246 }
3247
3248 //Overhead L1/2
3249 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3250 {
3251 for(int32_t k = 0; k < 2; ++k)
3252 {
3253 if(LayerMaskInt[k+1]!=0)
3254 {
3255 layermap=layer->layermap[k]-1;
3256
3257 if(layermap>-1 && layermap<map_count)
3258 {
3259 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3260 for(int32_t i=c; i<(c&0xF0)+16; i++)
3261 {
3262 auto data = TheMaps[layerscreen].data[i];
3263 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3264 auto cs = TheMaps[layerscreen].cset[i];
3265 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3266 }
3267 }
3268 }
3269 }
3270 }
3271
3272 for(int32_t k=4; k<6; k++)
3273 {
3274 if(LayerMaskInt[k+1]!=0)
3275 {
3276 layermap=layer->layermap[k]-1;
3277
3278 if(layermap>-1 && layermap<map_count)
3279 {
3280 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3281
3282 for(int32_t i=c; i<(c&0xF0)+16; i++)
3283 {
3284 auto data = TheMaps[layerscreen].data[i];
3285 auto cs = TheMaps[layerscreen].cset[i];
3286 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3287 }
3288 }
3289 }
3290 }
3291
3292 if(flags&cWALK)
3293 {
3294 if(LayerMaskInt[0]!=0)
3295 {
3296 for(int32_t i=c; i<(c&0xF0)+16; i++)
3297 {
3298 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3299 }
3300 }
3301
3302 for(int32_t k=0; k<2; k++)
3303 {
3304 if(LayerMaskInt[k+1]!=0)
3305 {
3306 for(int32_t i=c; i<(c&0xF0)+16; i++)
3307 {
3308 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3309 }
3310 }
3311 }
3312 }
3313
3314 if(flags&cFLAGS)
3315 {
3316 if(LayerMaskInt[CurrentLayer]!=0)
3317 {
3318 for(int32_t i=c; i<(c&0xF0)+16; i++)
3319 {
3320 if(CurrentLayer==0)
3321 {
3322 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3323 }
3324 else
3325 {
3326 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3327
3328 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3329 {
3330 if(i < 176)
3331 {
3332 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3333 TheMaps[_lscr].data[i],
3334 TheMaps[_lscr].cset[i], flags|dark,
3335 TheMaps[_lscr].sflag[i]);
3336 }
3337 else
3338 {
3339 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3340 }
3341 }
3342 }
3343 }
3344 }
3345
3346 /*
3347 if (LayerMaskInt[0]!=0) {
3348 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3349 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3350 }
3351 }
3352 */
3353 }
3354
3355 if(ShowMisalignments)
3356 {
3357 if(c<16)
3358 {
3359 check_alignments(dest,x,y,scr);
3360 }
3361 else if(c>159)
3362 {
3363 check_alignments(dest,x,y-160,scr);
3364 }
3365 }
3366 }
3367
3368 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3369 {
3370 if(map<0)
3371 map=cursor.map;
3372
3373 if(scr<0)
3374 scr=cursor.screen;
3375
3376 mapscr* layer=AbsoluteScr(map,scr);
3377 int32_t layermap=0, layerscreen=0;
3378
3379 if(!(layer->valid&mVALID))
3380 {
3381 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3382 rectfill(dest,x,y,x+15,y+175,vc(1));
3383 return;
3384 }
3385
3386 int32_t dark = layer->flags&4;
3387
3388 if(LayerMaskInt[0]==0)
3389 {
3390 rectfill(dest,x,y,x+15,y+175,0);
3391 }
3392
3393
3394 for(int32_t k=1; k<3; k++)
3395 {
3396 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3397 {
3398 layermap=layer->layermap[k]-1;
3399
3400 if(layermap>-1 && layermap<map_count)
3401 {
3402 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3403
3404 for(int32_t i=c; i<176; i+=16)
3405 {
3406 auto data = TheMaps[layerscreen].data[i];
3407 auto cs = TheMaps[layerscreen].cset[i];
3408 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3409 }
3410 }
3411 }
3412 }
3413
3414 if(LayerMaskInt[0]!=0)
3415 {
3416 for(int32_t i=c; i<176; i+=16)
3417 {
3418 word cmbdat = layer->data[i];
3419 byte cmbcset = layer->cset[i];
3420 int32_t cmbflag = layer->sflag[i];
3421 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3422 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3423 }
3424 }
3425
3426 for(int32_t k=0; k<2; k++)
3427 {
3428 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3429 {
3430 layermap=layer->layermap[k]-1;
3431
3432 if(layermap>-1 && layermap<map_count)
3433 {
3434 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3435
3436 for(int32_t i=c; i<176; i+=16)
3437 {
3438 auto data = TheMaps[layerscreen].data[i];
3439 auto cs = TheMaps[layerscreen].cset[i];
3440 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3441 }
3442 }
3443 }
3444 }
3445
3446 int32_t doortype[4];
3447
3448 for(int32_t i=0; i<4; i++)
3449 {
3450 switch(layer->door[i])
3451 {
3452 case dOPEN:
3453 doortype[i]=dt_pass;
3454 break;
3455
3456 case dLOCKED:
3457 doortype[i]=dt_lock;
3458 break;
3459
3460 case d1WAYSHUTTER:
3461 case dSHUTTER:
3462 doortype[i]=dt_shut;
3463 break;
3464
3465 case dBOSS:
3466 doortype[i]=dt_boss;
3467 break;
3468
3469 case dBOMB:
3470 doortype[i]=dt_bomb;
3471 break;
3472 }
3473 }
3474
3475 if((c&0x0F)==0)
3476 {
3477 switch(layer->door[left])
3478 {
3479
3480 case dBOMB:
3481 case dOPEN:
3482 case dLOCKED:
3483 case d1WAYSHUTTER:
3484 case dSHUTTER:
3485 case dBOSS:
3486 // put_door(dest,64,left,doortype[left],x+256,y,true);
3487 put_door(dest,64,left,doortype[left],x,y,true,scr);
3488 break;
3489 }
3490 }
3491 else if((c&0x0F)==15)
3492 {
3493 switch(layer->door[right])
3494 {
3495 case dBOMB:
3496 case dOPEN:
3497 case dLOCKED:
3498 case d1WAYSHUTTER:
3499 case dSHUTTER:
3500 case dBOSS:
3501 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3502 break;
3503 }
3504 }
3505
3506 for(int32_t k=2; k<4; k++)
3507 {
3508 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3509 {
3510 layermap=layer->layermap[k]-1;
3511
3512 if(layermap>-1 && layermap<map_count)
3513 {
3514 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3515
3516 for(int32_t i=c; i<176; i+=16)
3517 {
3518 auto data = TheMaps[layerscreen].data[i];
3519 auto cs = TheMaps[layerscreen].cset[i];
3520 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3521 }
3522 }
3523 }
3524 }
3525
3526 //Overhead L0
3527 if(LayerMaskInt[0]!=0)
3528 {
3529 for(int32_t i=c; i<176; i+=16)
3530 {
3531 auto data = TheMaps[layerscreen].data[i];
3532 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3533 auto cs = TheMaps[layerscreen].cset[i];
3534 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3535 }
3536 }
3537 //Overhead L1/2
3538 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3539 {
3540 for(int32_t k = 0; k < 2; ++k)
3541 {
3542 if(LayerMaskInt[k+1]!=0)
3543 {
3544 layermap=layer->layermap[k]-1;
3545
3546 if(layermap>-1 && layermap<map_count)
3547 {
3548 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3549 for(int32_t i=c; i<176; i+=16)
3550 {
3551 auto data = TheMaps[layerscreen].data[i];
3552 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3553 auto cs = TheMaps[layerscreen].cset[i];
3554 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3555 }
3556 }
3557 }
3558 }
3559 }
3560
3561
3562 for(int32_t k=4; k<6; k++)
3563 {
3564 if(LayerMaskInt[k+1]!=0)
3565 {
3566 layermap=layer->layermap[k]-1;
3567
3568 if(layermap>-1 && layermap<map_count)
3569 {
3570 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3571
3572 for(int32_t i=c; i<176; i+=16)
3573 {
3574 auto data = TheMaps[layerscreen].data[i];
3575 auto cs = TheMaps[layerscreen].cset[i];
3576 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3577 }
3578 }
3579 }
3580 }
3581
3582 if(flags&cWALK)
3583 {
3584 if(LayerMaskInt[0]!=0)
3585 {
3586 for(int32_t i=c&0xF; i<176; i+=16)
3587 {
3588 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3589 }
3590 }
3591
3592 for(int32_t k=0; k<2; k++)
3593 {
3594 if(LayerMaskInt[k+1]!=0)
3595 {
3596 for(int32_t i=c&0xF; i<176; i+=16)
3597 {
3598 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3599 }
3600 }
3601 }
3602 }
3603
3604 if(flags&cFLAGS)
3605 {
3606 if(LayerMaskInt[CurrentLayer]!=0)
3607 {
3608 for(int32_t i=c; i<176; i+=16)
3609 {
3610 if(CurrentLayer==0)
3611 {
3612 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3613 }
3614 else
3615 {
3616 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3617
3618 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3619 {
3620 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3621 TheMaps[_lscr].data[i],
3622 TheMaps[_lscr].cset[i], flags|dark,
3623 TheMaps[_lscr].sflag[i]);
3624 }
3625 }
3626 }
3627 }
3628 }
3629
3630 if(ShowMisalignments)
3631 {
3632 if((c&0x0F)==0)
3633 {
3634 check_alignments(dest,x,y,scr);
3635 }
3636 else if((c&0x0F)==15)
3637 {
3638 check_alignments(dest,x-240,y,scr);
3639 }
3640 }
3641 }
3642
3643 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3644 {
3645 if(map<0)
3646 map=cursor.map;
3647
3648 if(scr<0)
3649 scr=cursor.screen;
3650
3651 mapscr* layer=AbsoluteScr(map,scr);
3652 int32_t layermap=0, layerscreen=0;
3653
3654 if(!(layer->valid&mVALID))
3655 {
3656 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3657 rectfill(dest,x,y,x+15,y+15,vc(1));
3658 return;
3659 }
3660
3661 int32_t dark = layer->flags&4;
3662
3663 if(LayerMaskInt[0]!=0)
3664 {
3665 rectfill(dest,x,y,x+15,y+15,0);
3666 }
3667
3668 for(int32_t k=1; k<3; k++)
3669 {
3670 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3671 {
3672 layermap=layer->layermap[k]-1;
3673
3674 if(layermap>-1 && layermap<map_count)
3675 {
3676 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3677
3678 auto data = TheMaps[layerscreen].data[c];
3679 auto cs = TheMaps[layerscreen].cset[c];
3680 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3681 }
3682 }
3683 }
3684
3685 if(LayerMaskInt[0]!=0)
3686 {
3687 word cmbdat = layer->data[c];
3688 byte cmbcset = layer->cset[c];
3689 int32_t cmbflag = layer->sflag[c];
3690 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3691 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3692 }
3693
3694
3695 for(int32_t k=0; k<2; k++)
3696 {
3697 if(LayerMaskInt[k+1]!=0)
3698 {
3699 layermap=layer->layermap[k]-1;
3700
3701 if(layermap>-1 && layermap<map_count)
3702 {
3703 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3704
3705 auto data = TheMaps[layerscreen].data[c];
3706 auto cs = TheMaps[layerscreen].cset[c];
3707 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3708 }
3709 }
3710 }
3711
3712 for(int32_t k=2; k<4; k++)
3713 {
3714 if(LayerMaskInt[k+1]!=0)
3715 {
3716 layermap=layer->layermap[k]-1;
3717
3718 if(layermap>-1 && layermap<map_count)
3719 {
3720 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3721 auto data = TheMaps[layerscreen].data[c];
3722 auto cs = TheMaps[layerscreen].cset[c];
3723 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3724 }
3725 }
3726 }
3727
3728 //Overhead L0
3729 if(LayerMaskInt[0]!=0)
3730 {
3731 auto data = TheMaps[layerscreen].data[c];
3732 if(combo_class_buf[combobuf[data].type].overhead)
3733 {
3734 auto cs = TheMaps[layerscreen].cset[c];
3735 drawcombo(dest,x,y,data,cs,0,0);
3736 }
3737 }
3738 //Overhead L1/2
3739 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3740 {
3741 for(int32_t k = 0; k < 2; ++k)
3742 {
3743 if(LayerMaskInt[k+1]!=0)
3744 {
3745 layermap=layer->layermap[k]-1;
3746
3747 if(layermap>-1 && layermap<map_count)
3748 {
3749 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3750 auto data = TheMaps[layerscreen].data[c];
3751 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3752 auto cs = TheMaps[layerscreen].cset[c];
3753 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3754 }
3755 }
3756 }
3757 }
3758
3759
3760 for(int32_t k=4; k<6; k++)
3761 {
3762 if(LayerMaskInt[k+1]!=0)
3763 {
3764 layermap=layer->layermap[k]-1;
3765
3766 if(layermap>-1 && layermap<map_count)
3767 {
3768 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3769 auto data = TheMaps[layerscreen].data[c];
3770 auto cs = TheMaps[layerscreen].cset[c];
3771 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3772 }
3773 }
3774 }
3775
3776 if(flags&cWALK)
3777 {
3778 if(LayerMaskInt[0]!=0)
3779 {
3780 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3781 }
3782
3783 for(int32_t k=0; k<2; k++)
3784 {
3785 if(LayerMaskInt[k+1]!=0)
3786 {
3787 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3788 }
3789 }
3790 }
3791
3792 if(flags&cFLAGS)
3793 {
3794 if(LayerMaskInt[CurrentLayer]!=0)
3795 {
3796 int32_t i = c;
3797 //for(int32_t i=c; i==c; i++)
3798 {
3799 if(CurrentLayer==0)
3800 {
3801 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3802 }
3803 else
3804 {
3805 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3806
3807 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3808 {
3809 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3810 TheMaps[_lscr].data[i],
3811 TheMaps[_lscr].cset[i], flags|dark,
3812 TheMaps[_lscr].sflag[i]);
3813 }
3814 }
3815 }
3816 }
3817 }
3818
3819 if(ShowMisalignments)
3820 {
3821 switch(c)
3822 {
3823 case 0:
3824 check_alignments(dest,x,y,scr);
3825 break;
3826
3827 case 15:
3828 check_alignments(dest,x-240,y,scr);
3829 break;
3830
3831 case 160:
3832 check_alignments(dest,x,y-160,scr);
3833 break;
3834
3835 case 175:
3836 check_alignments(dest,x-240,y-160,scr);
3837 break;
3838 }
3839 }
3840 }
3841
3842 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3843 {
3844 if (InvalidBG == 2)
3845 {
3846 draw_checkerboard(dest, x, y, 16);
3847 }
3848 else if(InvalidBG == 1)
3849 {
3850 for(int32_t dy=0; dy<16; dy++)
3851 {
3852 for(int32_t dx=0; dx<16; dx++)
3853 {
3854 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3855 }
3856 }
3857 }
3858 else
3859 {
3860 rectfill(dest, x, y, x+15, y+15, vc(0));
3861 rect(dest, x, y, x+15, y+15, vc(15));
3862 line(dest, x, y, x+15, y+15, vc(15));
3863 line(dest, x, y+15, x+15, y, vc(15));
3864 }
3865 }
3866
3867 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3868 {
3869 if (InvalidBG == 2)
3870 {
3871 for(int32_t q = 0; q < 11; ++q)
3872 draw_checkerboard(dest, x, y + q * 16, 16);
3873 }
3874 else if(InvalidBG == 1)
3875 {
3876 for(int32_t dy=0; dy<176; dy++)
3877 {
3878 for(int32_t dx=0; dx<16; dx++)
3879 {
3880 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3881 }
3882 }
3883 }
3884 else
3885 {
3886 rectfill(dest, x, y, x+15, y+175, vc(0));
3887 rect(dest, x, y, x+15, y+175, vc(15));
3888 line(dest, x, y, x+15, y+175, vc(15));
3889 line(dest, x, y+175, x+15, y, vc(15));
3890 }
3891 }
3892
3893 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3894 {
3895 if (InvalidBG == 2)
3896 {
3897 for (int32_t q = 0; q < 16; ++q)
3898 draw_checkerboard(dest, x + q * 16, y, 16);
3899 }
3900 else if(InvalidBG == 1)
3901 {
3902 for(int32_t dy=0; dy<16; dy++)
3903 {
3904 for(int32_t dx=0; dx<256; dx++)
3905 {
3906 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3907 }
3908 }
3909 }
3910 else
3911 {
3912 rectfill(dest, x, y, x+255, y+15, vc(0));
3913 rect(dest, x, y, x+255, y+15, vc(15));
3914 line(dest, x, y, x+255, y+15, vc(15));
3915 line(dest, x, y+15, x+255, y, vc(15));
3916 }
3917 }
3918
3919 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3920 {
3921 for(int32_t i=0; i<176; i++)
3922 {
3923 word cmbdat = screens[TEMPLATE].data[i];
3924 byte cmbcset = screens[TEMPLATE].cset[i];
3925 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3926 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3927 }
3928 }
3929
3930 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3931 {
3932 for(int32_t i=0; i<176; i++)
3933 {
3934 word cmbdat = screens[TEMPLATE2].data[i];
3935 byte cmbcset = screens[TEMPLATE2].cset[i];
3936 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3937 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3938 }
3939 }
3940
3941 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3942 {
3943 word cmbdat = screens[TEMPLATE].data[pos];
3944 byte cmbcset = screens[TEMPLATE].cset[pos];
3945 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3946 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3947 }
3948
3949 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3950 {
3951 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3952 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3953 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3954 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3955 }
3956
3957 void zmap::scroll(int32_t dir, bool warp)
3958 {
3959 if(cursor.map<map_count)
3960 {
3961 switch(dir)
3962 {
3963 case up:
3964 if(warp && Map.CurrScr()->flags2&wfUP)
3965 {
3966 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3967 }
3968 else if(cursor.screen>15)
3969 {
3970 setCurrScr(cursor.screen - 16);
3971 }
3972
3973 break;
3974
3975 case down:
3976 if(warp && Map.CurrScr()->flags2&wfDOWN)
3977 {
3978 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3979 }
3980 else if(cursor.screen<MAPSCRS-16)
3981 {
3982 setCurrScr(cursor.screen + 16);
3983 }
3984
3985 break;
3986
3987 case left:
3988 if(warp && Map.CurrScr()->flags2&wfLEFT)
3989 {
3990 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3991 }
3992 else if(cursor.screen&15)
3993 {
3994 setCurrScr(cursor.screen - 1);
3995 }
3996
3997 break;
3998
3999 case right:
4000 if(warp && Map.CurrScr()->flags2&wfRIGHT)
4001 {
4002 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
4003 }
4004 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
4005 {
4006 setCurrScr(cursor.screen + 1);
4007 }
4008
4009 break;
4010 }
4011 }
4012 }
4013
4014 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
4015 {
4016 switch(side)
4017 {
4018 case up:
4019 switch(door)
4020 {
4021 case dWALL:
4022 case dBOMB:
4023 case dWALK:
4024 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
4025 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
4026 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
4027 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
4028 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
4029 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
4030 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
4031 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
4032 break;
4033
4034 default:
4035 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
4036 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
4037 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
4038 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
4039 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
4040 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
4041 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
4042 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
4043 break;
4044 }
4045
4046 break;
4047
4048 case down:
4049 switch(door)
4050 {
4051 case dWALL:
4052 case dBOMB:
4053 case dWALK:
4054 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4055 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4056 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4057 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4058 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4059 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4060 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4061 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4062 break;
4063
4064 default:
4065 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4066 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4067 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4068 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4069 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4070 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4071 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4072 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4073 break;
4074 }
4075
4076 break;
4077
4078 case left:
4079 switch(door)
4080 {
4081 case dWALL:
4082 case dBOMB:
4083 case dWALK:
4084 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4085 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4086 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4087 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4088 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4089 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4090 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4091 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4092 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4093 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4094 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4095 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4096 break;
4097
4098 default:
4099 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4100 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4101 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4102 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4103 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4104 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4105 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4106 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4107 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4108 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4109 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4110 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4111 break;
4112 }
4113
4114 break;
4115
4116 case right:
4117 switch(door)
4118 {
4119 case dWALL:
4120 case dBOMB:
4121 case dWALK:
4122 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4123 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4124 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4125 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4126 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4127 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4128 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4129 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4130 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4131 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4132 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4133 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4134 break;
4135
4136 default:
4137 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4138 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4139 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4140 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4141 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4142 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4143 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4144 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4145 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4146 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4147 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4148 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4149 break;
4150 }
4151
4152 break;
4153 }
4154 }
4155 void zmap::DoPutDoorCommand(int side, int door, bool force)
4156 {
4157 if(!force && screens[cursor.screen].door[side] == door)
4158 return;
4159 bool already_list = InListCommand();
4160 if(!already_list)
4161 StartListCommand();
4162 DoSetDoorCommand(cursor.screen,side,door);
4163 if(door != dNONE)
4164 {
4165 word data[176] = {0};
4166 byte cset[176] = {0};
4167 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4168 for(int q = 0; q < 176; ++q)
4169 if(data[q])
4170 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4171 }
4172 if(!already_list)
4173 FinishListCommand();
4174 }
4175 void zmap::putdoor(int32_t scr,int32_t side,int32_t door)
4176 {
4177 if(screens[scr].door[side] == door)
4178 return;
4179 screens[scr].door[side] = door;
4180 if(door != dNONE)
4181 {
4182 word data[176] = {0};
4183 byte cset[176] = {0};
4184 fetch_door(side, door, screens[scr].door_combo_set, data, cset);
4185 for(int q = 0; q < 176; ++q)
4186 if(data[q])
4187 {
4188 screens[scr].data[q] = data[q];
4189 screens[scr].cset[q] = cset[q];
4190 }
4191 }
4192 }
4193
4194 void list_command::execute()
4195 {
4196 for (auto command : commands)
4197 {
4198 command->execute();
4199 }
4200 }
4201
4202 void list_command::undo()
4203 {
4204 for (int i = commands.size() - 1; i >= 0; i--)
4205 {
4206 commands[i]->undo();
4207 }
4208 }
4209
4210 int list_command::size()
4211 {
4212 int s = 0;
4213 for (auto command : commands)
4214 {
4215 s += command->size();
4216 }
4217 return s;
4218 }
4219
4220 void set_combo_command::execute()
4221 {
4222 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4223 if (!scr_ptr) return;
4224
4225 if (combo != -1) scr_ptr->data[pos] = combo;
4226 scr_ptr->cset[pos] = cset;
4227 }
4228
4229 void set_combo_command::undo()
4230 {
4231 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4232 if(!mapscr_ptr) return;
4233 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4234 mapscr_ptr->cset[pos] = prev_cset;
4235 }
4236
4237 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4238 {
4239 std::array<int, 2> inita_arr;
4240 std::copy(std::begin(ffc.inita), std::end(ffc.inita), inita_arr.begin());
4241 std::array<int, 8> initd_arr;
4242 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4243
4244 return {
4245 .x = ffc.x,
4246 .y = ffc.y,
4247 .vx = ffc.vx,
4248 .vy = ffc.vy,
4249 .ax = ffc.ax,
4250 .ay = ffc.ay,
4251 .data = ffc.data,
4252 .cset = ffc.cset,
4253 .delay = ffc.delay,
4254 .link = ffc.link,
4255 .script = ffc.script,
4256 .tw = ffc.txsz,
4257 .th = ffc.tysz,
4258 .ew = ffc.hit_width,
4259 .eh = ffc.hit_height,
4260 .flags = ffc.flags,
4261 .inita = inita_arr,
4262 .initd = initd_arr,
4263 };
4264 }
4265
4266 void set_ffc_command::execute()
4267 {
4268 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4269 if(!mapscr_ptr) return;
4270
4271 mapscr_ptr->valid |= mVALID;
4272 mapscr_ptr->ffcs[i].x = data.x;
4273 mapscr_ptr->ffcs[i].y = data.y;
4274 mapscr_ptr->ffcs[i].vx = data.vx;
4275 mapscr_ptr->ffcs[i].vy = data.vy;
4276 mapscr_ptr->ffcs[i].ax = data.ax;
4277 mapscr_ptr->ffcs[i].ay = data.ay;
4278 mapscr_ptr->ffcs[i].data = data.data;
4279 mapscr_ptr->ffcs[i].cset = data.cset;
4280 mapscr_ptr->ffcs[i].delay = data.delay;
4281 mapscr_ptr->ffcs[i].link = data.link;
4282 mapscr_ptr->ffcs[i].script = data.script;
4283 mapscr_ptr->ffcs[i].flags = data.flags;
4284 mapscr_ptr->ffEffectWidth(i, data.ew);
4285 mapscr_ptr->ffEffectHeight(i, data.eh);
4286 mapscr_ptr->ffTileWidth(i, data.tw);
4287 mapscr_ptr->ffTileHeight(i, data.th);
4288 std::copy(std::begin(data.inita), std::end(data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4289 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4290 mapscr_ptr->ffcCountMarkDirty();
4291 mapscr_ptr->ffcs[i].updateSolid();
4292 }
4293
4294 void set_ffc_command::undo()
4295 {
4296 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4297 if(!mapscr_ptr) return;
4298
4299 mapscr_ptr->ffcs[i].x = prev_data.x;
4300 mapscr_ptr->ffcs[i].y = prev_data.y;
4301 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4302 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4303 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4304 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4305 mapscr_ptr->ffcs[i].data = prev_data.data;
4306 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4307 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4308 mapscr_ptr->ffcs[i].link = prev_data.link;
4309 mapscr_ptr->ffcs[i].script = prev_data.script;
4310 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4311 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4312 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4313 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4314 mapscr_ptr->ffTileHeight(i, prev_data.th);
4315 std::copy(std::begin(prev_data.inita), std::end(prev_data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4316 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4317 mapscr_ptr->ffcCountMarkDirty();
4318 mapscr_ptr->ffcs[i].updateSolid();
4319 }
4320
4321 void set_flag_command::execute()
4322 {
4323 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4324 if(!mapscr_ptr) return;
4325
4326 mapscr_ptr->valid |= mVALID;
4327 mapscr_ptr->sflag[pos] = flag;
4328 }
4329
4330 void set_flag_command::undo()
4331 {
4332 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4333 if(!mapscr_ptr) return;
4334 mapscr_ptr->sflag[pos] = prev_flag;
4335 }
4336
4337 void set_door_command::execute()
4338 {
4339 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4340 if(!mapscr_ptr) return;
4341
4342 mapscr_ptr->valid |= mVALID;
4343 mapscr_ptr->door[side] = door;
4344 }
4345
4346 void set_door_command::undo()
4347 {
4348 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4349 }
4350
4351 void set_dcs_command::execute()
4352 {
4353 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4354 if(!mapscr_ptr) return;
4355
4356 mapscr_ptr->valid |= mVALID;
4357 mapscr_ptr->door_combo_set = dcs;
4358 }
4359
4360 void set_dcs_command::undo()
4361 {
4362 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4363 }
4364
4365 void paste_screen_command::execute()
4366 {
4367 perform(screen.get());
4368 }
4369
4370 void paste_screen_command::undo()
4371 {
4372 if (prev_screens.size() > 1)
4373 {
4374 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4375 ASSERT(prev_screens.size() == 128);
4376 for (int i = 0; i < 128; i++)
4377 {
4378 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4379 // TODO: why not just this?
4380 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4381 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4382 }
4383 return;
4384 }
4385
4386 perform(prev_screens[0].get());
4387 }
4388
4389 int paste_screen_command::size()
4390 {
4391 return prev_screens.size() + 1;
4392 }
4393
4394 void paste_screen_command::perform(mapscr* to)
4395 {
4396 if (to)
4397 {
4398 switch (type) {
4399 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4400 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4401 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4402 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4403 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4404 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4405 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4406 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4407 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4408 case ScreenPartial: Map.Paste(*to, screen_index); break;
4409 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4410 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4411 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4412 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4413 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4414 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4415 }
4416 }
4417 else
4418 {
4419 Map.clearscr(screen_index);
4420 }
4421 refresh(rALL);
4422 }
4423
4424 void set_screen_command::execute()
4425 {
4426 if (screen)
4427 {
4428 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4429 }
4430 else
4431 {
4432 Map.clearscr(screen_index);
4433 }
4434 refresh(rALL);
4435 }
4436
4437 void set_screen_command::undo()
4438 {
4439 if (prev_screen)
4440 {
4441 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4442 }
4443 else
4444 {
4445 Map.clearscr(screen_index);
4446 }
4447 refresh(rALL);
4448 }
4449
4450 int set_screen_command::size()
4451 {
4452 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4453 }
4454
4455 static std::shared_ptr<list_command> current_list_command;
4456 void zmap::StartListCommand()
4457 {
4458 ASSERT(!current_list_command);
4459 current_list_command.reset(new list_command);
4460 }
4461
4462 void zmap::FinishListCommand()
4463 {
4464 if (current_list_command->commands.size() == 1)
4465 {
4466 undo_stack.push_back(current_list_command->commands[0]);
4467 }
4468 else if (current_list_command->commands.size() > 1)
4469 {
4470 undo_stack.push_back(current_list_command);
4471 }
4472 CapCommandHistory();
4473 current_list_command = nullptr;
4474 }
4475
4476 void zmap::RevokeListCommand()
4477 {
4478 current_list_command->undo();
4479 current_list_command = nullptr;
4480 }
4481
4482 bool zmap::InListCommand() const
4483 {
4484 return current_list_command ? true : false;
4485 }
4486
4487 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4488 {
4489 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4490 if (!skip_execute) command->execute();
4491 if (current_list_command)
4492 {
4493 current_list_command->commands.push_back(command);
4494 if (current_list_command->commands.size() == 1)
4495 {
4496 current_list_command->cursor = command->cursor;
4497 }
4498 }
4499 else
4500 {
4501 undo_stack.push_back(command);
4502 CapCommandHistory();
4503 }
4504 saved = false;
4505 }
4506
4507 void zmap::UndoCommand()
4508 {
4509 if (undo_stack.size() <= 0) return;
4510
4511 // If not currently looking at the associated screen, first change the view
4512 // and wait for the next call to actually undo this command.
4513 auto command = undo_stack.back();
4514 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4515 {
4516 setCursor(command.get()->cursor);
4517 return;
4518 }
4519
4520 command->undo();
4521 redo_stack.push(command);
4522 undo_stack.pop_back();
4523 saved = false;
4524 }
4525
4526 void zmap::RedoCommand()
4527 {
4528 if (redo_stack.size() <= 0) return;
4529
4530 // If not currently selected the associated screen, first change the cursor
4531 // and wait for the next call to actually execute this command.
4532 auto command = redo_stack.top();
4533 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4534 {
4535 setCursor(command.get()->cursor);
4536 return;
4537 }
4538
4539 command->execute();
4540 undo_stack.push_back(command);
4541 redo_stack.pop();
4542 saved = false;
4543 }
4544
4545 9 void zmap::ClearCommandHistory()
4546 {
4547 9 current_list_command = nullptr;
4548 9 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4549 9 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4550 9 }
4551
4552 // Extra amount is from mapscr's vectors.
4553 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4554 // Allow the undo system to use roughly 100 MB of memory.
4555 // This doesn't count the memory used by commands that don't store a mapscr,
4556 // but that should be negligible.
4557 9 static int max_command_size = 100e6 / size_of_mapscr;
4558 void zmap::CapCommandHistory()
4559 {
4560 int size;
4561 do
4562 {
4563 size = 0;
4564 for (auto command : undo_stack)
4565 {
4566 size += command->size();
4567 }
4568 if (size > max_command_size) undo_stack.pop_front();
4569 } while (size > max_command_size);
4570 }
4571
4572 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4573 {
4574 if (!pos.is_valid(cursor))
4575 return;
4576
4577 int map = cursor.map;
4578 int screen = cursor.viewscr + pos.screen_offset();
4579 if (!AbsoluteScr(map, screen))
4580 return;
4581
4582 if (CurrentLayer)
4583 {
4584 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4585 map = scr->layermap[CurrentLayer-1]-1;
4586 screen = scr->layerscreen[CurrentLayer-1];
4587 }
4588 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4589 }
4590
4591 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4592 {
4593 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4594 if (!mapscr_ptr) return;
4595
4596 std::shared_ptr<set_combo_command> command(new set_combo_command);
4597 command->cursor = cursor;
4598 command->map = map;
4599 command->scr = scr;
4600 command->pos = pos;
4601 command->combo = combo;
4602 command->cset = cset;
4603 command->prev_combo = mapscr_ptr->data[pos];
4604 command->prev_cset = mapscr_ptr->cset[pos];
4605 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4606 {
4607 // nothing to do...
4608 return;
4609 }
4610
4611 ExecuteCommand(command);
4612 }
4613
4614 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4615 {
4616 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4617 if(!mapscr_ptr) return;
4618
4619 mapscr_ptr->ensureFFC(i);
4620
4621 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4622
4623 std::array<int, 2> inita_arr;
4624 std::copy(std::begin(mapscr_ptr->ffcs[i].inita), std::end(mapscr_ptr->ffcs[i].inita), inita_arr.begin());
4625 std::array<int, 8> initd_arr;
4626 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4627
4628 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4629
4630 command->cursor = cursor;
4631 command->map = map;
4632 command->scr = scr;
4633 command->i = i;
4634 command->data = data;
4635 command->prev_data = prev_data;
4636 if (data == prev_data)
4637 {
4638 // nothing to do...
4639 return;
4640 }
4641
4642 ExecuteCommand(command);
4643 }
4644
4645 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4646 {
4647 if (!pos.is_valid(cursor))
4648 return;
4649
4650 int map = cursor.map;
4651 int screen = cursor.viewscr + pos.screen_offset();
4652 if (!AbsoluteScr(map, screen))
4653 return;
4654
4655 if (CurrentLayer)
4656 {
4657 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4658 map = scr->layermap[CurrentLayer-1]-1;
4659 screen = scr->layerscreen[CurrentLayer-1];
4660 }
4661 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4662 }
4663
4664 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4665 {
4666 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4667 if(!mapscr_ptr) return;
4668
4669 std::shared_ptr<set_flag_command> command(new set_flag_command);
4670 command->cursor = cursor;
4671 command->map = map;
4672 command->scr = scr;
4673 command->pos = pos;
4674 command->flag = flag;
4675 command->prev_flag = mapscr_ptr->sflag[pos];
4676 if (command->flag == command->prev_flag)
4677 {
4678 // nothing to do...
4679 return;
4680 }
4681
4682 ExecuteCommand(command);
4683 }
4684
4685 void zmap::DoSetDoorCommand(int scr, int side, int door)
4686 {
4687 if(screens[scr].door[side] == door)
4688 return;
4689 std::shared_ptr<set_door_command> command(new set_door_command);
4690 command->cursor = cursor;
4691 command->side = side;
4692 command->door = door;
4693 command->prev_door = screens[scr].door[side];
4694
4695 ExecuteCommand(command);
4696 }
4697 void zmap::DoSetDCSCommand(int dcs)
4698 {
4699 if(screens[cursor.screen].door_combo_set == dcs)
4700 return;
4701 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4702 command->cursor = cursor;
4703 command->dcs = dcs;
4704 command->prev_dcs = screens[cursor.screen].door_combo_set;
4705
4706 ExecuteCommand(command);
4707 }
4708
4709 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4710 {
4711 if (screen == -1)
4712 screen = cursor.screen;
4713
4714 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4715 command->cursor = cursor;
4716 command->type = type;
4717 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4718 command->screen_index = screen;
4719
4720 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4721 {
4722 for (int i=0; i < 128; i++)
4723 {
4724 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4725 }
4726 }
4727 else
4728 {
4729 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4730 }
4731
4732 ExecuteCommand(command);
4733 }
4734
4735 void zmap::DoClearScreenCommand(int screen)
4736 {
4737 std::shared_ptr<set_screen_command> command(new set_screen_command);
4738 command->cursor = cursor;
4739 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4740 command->screen = std::shared_ptr<mapscr>(nullptr);
4741 command->screen_index = screen;
4742
4743 ExecuteCommand(command);
4744 }
4745
4746 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4747 {
4748 std::shared_ptr<set_screen_command> command(new set_screen_command);
4749 command->cursor = cursor;
4750 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4751 Template(floorcombo, floorcset, screen);
4752 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4753
4754 ExecuteCommand(command, true);
4755 }
4756
4757 void zmap::Copy(int scr)
4758 {
4759 if(screens[scr].valid&mVALID)
4760 {
4761 copy_mapscr(&copymapscr, &screens[scr]);
4762 //copymapscr=screens[scr];
4763 can_paste=true;
4764 copymap=cursor.map;
4765 copyscr=scr;
4766 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4767 copyffc = -1;
4768 }
4769 }
4770
4771 void zmap::CopyFFC(int32_t screen, int32_t n)
4772 {
4773 if(screens[screen].valid&mVALID)
4774 {
4775 copy_mapscr(&copymapscr, &screens[screen]);
4776 // Can't paste the screen itself
4777 can_paste = false;
4778 copymap=cursor.map;
4779 copyscr=screen;
4780 copyffc = n;
4781 }
4782 }
4783
4784 void zmap::Paste(const mapscr& copymapscr, int screen)
4785 {
4786 if(can_paste)
4787 {
4788 int32_t oldcolor=getcolor();
4789
4790 if(!(screens[screen].valid&mVALID))
4791 {
4792 screens[screen].valid |= mVALID;
4793 screens[screen].color = copymapscr.color;
4794 }
4795
4796 screens[screen].door_combo_set = copymapscr.door_combo_set;
4797
4798 for(int32_t i=0; i<4; i++)
4799 {
4800 screens[screen].door[i]=copymapscr.door[i];
4801 }
4802
4803 for(int32_t i=0; i<176; i++)
4804 {
4805 screens[screen].data[i] = copymapscr.data[i];
4806 screens[screen].cset[i] = copymapscr.cset[i];
4807 screens[screen].sflag[i] = copymapscr.sflag[i];
4808 }
4809
4810 int32_t newcolor=getcolor();
4811 loadlvlpal(newcolor);
4812
4813 if(newcolor!=oldcolor)
4814 {
4815 rebuild_trans_table();
4816 }
4817
4818 saved=false;
4819 }
4820 }
4821
4822 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4823 {
4824 if(can_paste)
4825 {
4826 screens[screen].undercombo = copymapscr.undercombo;
4827 screens[screen].undercset = copymapscr.undercset;
4828 saved=false;
4829 }
4830 }
4831
4832 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4833 {
4834 if(can_paste)
4835 {
4836 for(int32_t i=0; i<128; i++)
4837 {
4838 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4839 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4840 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4841 }
4842
4843 saved=false;
4844 }
4845 }
4846
4847 // TODO const mapscr& copymapscr
4848 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4849 {
4850 if(can_paste)
4851 {
4852 screens[screen].ffcs = copymapscr.ffcs;
4853 screens[screen].ffcCountMarkDirty();
4854 saved=false;
4855 }
4856 }
4857
4858 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4859 {
4860 if(can_paste)
4861 {
4862 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4863
4864 for(int32_t i=0; i<4; i++)
4865 {
4866 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4867 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4868 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4869 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4870 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4871 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4872 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4873 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4874 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4875 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4876 }
4877
4878 saved=false;
4879 }
4880 }
4881
4882 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4883 {
4884 if(can_paste)
4885 {
4886 screens[screen].csensitive = copymapscr.csensitive;
4887 screens[screen].oceansfx = copymapscr.oceansfx;
4888 screens[screen].bosssfx = copymapscr.bosssfx;
4889 screens[screen].secretsfx = copymapscr.secretsfx;
4890 screens[screen].holdupsfx = copymapscr.holdupsfx;
4891 screens[screen].flags = copymapscr.flags;
4892 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4893 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4894 screens[screen].flags3 = copymapscr.flags3;
4895 screens[screen].flags4 = copymapscr.flags4;
4896 screens[screen].flags5 = copymapscr.flags5;
4897 screens[screen].flags6 = copymapscr.flags6;
4898 screens[screen].flags7 = copymapscr.flags7;
4899 screens[screen].flags8 = copymapscr.flags8;
4900 screens[screen].flags9 = copymapscr.flags9;
4901 screens[screen].flags10 = copymapscr.flags10;
4902 screens[screen].item = copymapscr.item;
4903 screens[screen].hasitem = copymapscr.hasitem;
4904 screens[screen].itemx = copymapscr.itemx;
4905 screens[screen].itemy = copymapscr.itemy;
4906 screens[screen].nextmap = copymapscr.nextmap;
4907 screens[screen].nextscr = copymapscr.nextscr;
4908 screens[screen].nocarry = copymapscr.nocarry;
4909 screens[screen].noreset = copymapscr.noreset;
4910 screens[screen].path[0] = copymapscr.path[0];
4911 screens[screen].path[1] = copymapscr.path[1];
4912 screens[screen].path[2] = copymapscr.path[2];
4913 screens[screen].path[3] = copymapscr.path[3];
4914 screens[screen].pattern = copymapscr.pattern;
4915 screens[screen].exitdir = copymapscr.exitdir;
4916 screens[screen].enemyflags = copymapscr.enemyflags;
4917 screens[screen].screen_midi = copymapscr.screen_midi;
4918 screens[screen].stairx = copymapscr.stairx;
4919 screens[screen].stairy = copymapscr.stairy;
4920 screens[screen].timedwarptics = copymapscr.timedwarptics;
4921 saved=false;
4922 }
4923 }
4924
4925 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4926 {
4927 if(can_paste)
4928 {
4929 screens[screen].warpreturnc = copymapscr.warpreturnc;
4930 screens[screen].warparrivalx = copymapscr.warparrivalx;
4931 screens[screen].warparrivaly = copymapscr.warparrivaly;
4932
4933 for(int32_t i=0; i<4; i++)
4934 {
4935 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4936 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4937 }
4938
4939 saved=false;
4940 }
4941 }
4942
4943 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4944 {
4945 if(can_paste)
4946 {
4947 for(int32_t i=0; i<4; i++)
4948 screens[screen].door[i] = copymapscr.door[i];
4949
4950 screens[screen].door_combo_set = copymapscr.door_combo_set;
4951 saved=false;
4952 }
4953 }
4954
4955 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4956 {
4957 if(can_paste)
4958 {
4959 for(int32_t i=0; i<6; i++)
4960 {
4961 screens[screen].layermap[i] = copymapscr.layermap[i];
4962 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4963 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4964 }
4965
4966 saved=false;
4967 }
4968 }
4969
4970 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4971 {
4972 if(can_paste)
4973 {
4974 screens[screen].room = copymapscr.room;
4975 screens[screen].catchall = copymapscr.catchall;
4976 saved=false;
4977 }
4978 }
4979
4980 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4981 {
4982 if(can_paste)
4983 {
4984 screens[screen].guy = copymapscr.guy;
4985 screens[screen].guytile = copymapscr.guytile;
4986 screens[screen].guycs = copymapscr.guycs;
4987 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4988 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4989 screens[screen].str = copymapscr.str;
4990 saved=false;
4991 }
4992 }
4993
4994 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4995 {
4996 if(can_paste)
4997 {
4998 int32_t oldcolor=getcolor();
4999 screens[screen].color = copymapscr.color;
5000 int32_t newcolor=getcolor();
5001 loadlvlpal(newcolor);
5002
5003 screens[screen].valid|=mVALID;
5004
5005 if(newcolor!=oldcolor)
5006 {
5007 rebuild_trans_table();
5008 }
5009
5010 saved=false;
5011 }
5012 }
5013
5014 void zmap::PasteAll(const mapscr& copymapscr, int screen)
5015 {
5016 if(can_paste)
5017 {
5018 int32_t oldcolor=getcolor();
5019 copy_mapscr(&screens[screen], &copymapscr);
5020 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
5021 //screens[screen]=copymapscr;
5022 int32_t newcolor=getcolor();
5023 loadlvlpal(newcolor);
5024
5025 screens[screen].valid|=mVALID;
5026
5027 if(newcolor!=oldcolor)
5028 {
5029 rebuild_trans_table();
5030 }
5031
5032 saved=false;
5033 }
5034 }
5035
5036
5037 void zmap::PasteToAll(const mapscr& copymapscr)
5038 {
5039 if(can_paste)
5040 {
5041 int32_t oldcolor=getcolor();
5042
5043 for(int32_t x=0; x<128; x++)
5044 {
5045 if(!(screens[x].valid&mVALID))
5046 {
5047 screens[x].valid |= mVALID;
5048 screens[x].color = copymapscr.color;
5049 }
5050
5051 for(int32_t i=0; i<176; i++)
5052 {
5053 screens[x].data[i] = copymapscr.data[i];
5054 screens[x].cset[i] = copymapscr.cset[i];
5055 screens[x].sflag[i] = copymapscr.sflag[i];
5056 }
5057 }
5058
5059 int32_t newcolor=getcolor();
5060 loadlvlpal(newcolor);
5061
5062 if(!(screens[cursor.screen].valid&mVALID))
5063 {
5064 newcolor=-1;
5065 }
5066
5067 if(newcolor!=oldcolor)
5068 {
5069 rebuild_trans_table();
5070 }
5071
5072 saved=false;
5073 }
5074 }
5075
5076 void zmap::PasteAllToAll(const mapscr& copymapscr)
5077 {
5078 if(can_paste)
5079 {
5080 int32_t oldcolor=getcolor();
5081
5082 for(int32_t x=0; x<128; x++)
5083 {
5084 copy_mapscr(&screens[x], &copymapscr);
5085 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
5086 //screens[x]=copymapscr;
5087 }
5088
5089 int32_t newcolor=getcolor();
5090 loadlvlpal(newcolor);
5091
5092 if(!(screens[cursor.screen].valid&mVALID))
5093 {
5094 newcolor=-1;
5095 }
5096
5097 if(newcolor!=oldcolor)
5098 {
5099 rebuild_trans_table();
5100 }
5101
5102 saved=false;
5103 }
5104 }
5105
5106 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
5107 {
5108 if(can_paste)
5109 {
5110 for(int32_t i=0; i<10; i++)
5111 screens[screen].enemy[i]=copymapscr.enemy[i];
5112 }
5113 }
5114
5115 void zmap::setCopyFFC(int32_t n)
5116 {
5117 copyffc = n;
5118 }
5119
5120 void zmap::update_combo_cycling()
5121 {
5122 if(!prv_mode||!prv_cmbcycle)
5123 {
5124 return;
5125 }
5126
5127 int32_t x;
5128 int32_t newdata[176];
5129 int32_t newcset[176];
5130 bool restartanim[MAXCOMBOS] = {0};
5131
5132 for(int32_t i=0; i<176; i++)
5133 {
5134 newdata[i]=-1;
5135 newcset[i]=-1;
5136
5137 x=prvscr.data[i];
5138
5139 //time to restart
5140 if((combobuf[x].aclk>=combobuf[x].speed) &&
5141 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5142 (combobuf[x].nextcombo!=0))
5143 {
5144 newdata[i]=combobuf[x].nextcombo;
5145 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5146 newcset[i]=combobuf[x].nextcset;
5147 int32_t c = newdata[i];
5148
5149 if(combobuf[c].animflags & AF_CYCLE)
5150 {
5151 restartanim[c]=true;
5152 }
5153 }
5154 }
5155
5156 for(int32_t i=0; i<176; i++)
5157 {
5158 x=prvscr.data[i];
5159
5160 //time to restart
5161 if((combobuf[x].aclk>=combobuf[x].speed) &&
5162 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5163 (combobuf[x].nextcombo!=0))
5164 {
5165 newdata[i]=combobuf[x].nextcombo;
5166 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5167 newcset[i]=combobuf[x].nextcset;
5168 int32_t c = newdata[i];
5169
5170 if(combobuf[c].animflags & AF_CYCLE)
5171 {
5172 restartanim[c]=true;
5173 }
5174 }
5175 }
5176
5177 for(int32_t i=0; i<176; i++)
5178 {
5179 if(newdata[i]==-1)
5180 continue;
5181
5182 prvscr.data[i]=newdata[i];
5183 prvscr.cset[i]=newcset[i];
5184 }
5185
5186 word maxffc = prvscr.numFFC();
5187 for(word i=0; i<maxffc; i++)
5188 {
5189 ffcdata& ffc = prvscr.ffcs[i];
5190 newcombo const& cmb = combobuf[ffc.data];
5191
5192 //time to restart
5193 if((cmb.aclk>=cmb.speed) &&
5194 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5195 (cmb.nextcombo!=0))
5196 {
5197 ffc.data = cmb.nextcombo;
5198 if(!(cmb.animflags & AF_CYCLENOCSET))
5199 ffc.cset=cmb.nextcset;
5200
5201 if(combobuf[ffc.data].animflags & AF_CYCLE)
5202 {
5203 restartanim[ffc.data]=true;
5204 }
5205 prvscr.ffcs[i].data = ffc.data;
5206 prvscr.ffcs[i].cset=ffc.cset;
5207 }
5208 }
5209
5210
5211 if(get_qr(qr_CMBCYCLELAYERS))
5212 {
5213 for(int32_t j=0; j<6; j++)
5214 {
5215 if(!prvlayers[j].valid)
5216 continue;
5217
5218 for(int32_t i=0; i<176; i++)
5219 {
5220 newdata[i]=-1;
5221 newcset[i]=-1;
5222
5223 x=(prvlayers[j]).data[i];
5224
5225 //time to restart
5226 if((combobuf[x].aclk>=combobuf[x].speed) &&
5227 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5228 (combobuf[x].nextcombo!=0))
5229 {
5230 newdata[i]=combobuf[x].nextcombo;
5231 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5232 newcset[i]=combobuf[x].nextcset;
5233 int32_t c = newdata[i];
5234
5235 if(combobuf[c].animflags & AF_CYCLE)
5236 {
5237 restartanim[c]=true;
5238 }
5239 }
5240 }
5241
5242 for(int32_t i=0; i<176; i++)
5243 {
5244 x=(prvlayers[j]).data[i];
5245
5246 //time to restart
5247 if((combobuf[x].aclk>=combobuf[x].speed) &&
5248 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5249 (combobuf[x].nextcombo!=0))
5250 {
5251 newdata[i]=combobuf[x].nextcombo;
5252 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5253 newcset[i]=combobuf[x].nextcset;
5254 int32_t c = newdata[i];
5255
5256 if(combobuf[c].animflags & AF_CYCLE)
5257 {
5258 restartanim[c]=true;
5259 }
5260 }
5261 }
5262
5263 for(int32_t i=0; i<176; i++)
5264 {
5265 if(newdata[i]==-1)
5266 continue;
5267
5268 prvlayers[j].data[i]=newdata[i];
5269 prvlayers[j].cset[i]=newcset[i];
5270 }
5271 }
5272 }
5273
5274 for(int32_t i=0; i<MAXCOMBOS; i++)
5275 {
5276 if(restartanim[i])
5277 {
5278 combobuf[i].tile = combobuf[i].o_tile;
5279 combobuf[i].cur_frame=0;
5280 combobuf[i].aclk = 0;
5281 }
5282 }
5283 }
5284
5285 void zmap::update_freeform_combos()
5286 {
5287 if(!prv_mode||!prv_cmbcycle)
5288 {
5289 return;
5290 }
5291
5292 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5293 word maxffc = prvscr.numFFC();
5294 for(int32_t i=0; i<maxffc; i++)
5295 {
5296 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5297 {
5298 for(int32_t j=0; j<maxffc; j++)
5299 {
5300 if(i!=j)
5301 {
5302 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5303 {
5304 if((((prvscr.ffcs[j].x.getInt())!=ffposx[i])||((prvscr.ffcs[j].y.getInt())!=ffposy[i]))&&(prvscr.ffcs[i].link==0))
5305 {
5306 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),ffprvx[i],ffprvy[i],prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5307 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(ffprvx[i]>-10000000&&ffprvy[i]>-10000000))
5308 {
5309 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5310 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5311 if(prvscr.ffcs[j].flags&ffc_changethis)
5312 {
5313 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5314 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5315 }
5316
5317 if(prvscr.ffcs[j].flags&ffc_changenext)
5318 prvscr.ffcs[i].data += 1;
5319
5320 if(prvscr.ffcs[j].flags&ffc_changeprev)
5321 prvscr.ffcs[i].data -= 1;
5322
5323 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5324 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5325 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5326
5327 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5328 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5329 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5330 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5331
5332 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5333 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5334 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5335 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5336 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5337
5338 if(prvscr.ffcs[i].flags&ffc_carryover)
5339 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5340 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5341
5342 prvscr.ffcs[i].flags&=~ffc_changer;
5343 ffposx[i]=(prvscr.ffcs[j].x.getInt());
5344 ffposy[i]=(prvscr.ffcs[j].y.getInt());
5345
5346 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5347 {
5348 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5349 }
5350
5351 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5352 {
5353 int32_t k=0;
5354
5355 if(prvscr.ffcs[j].flags&ffc_swapnext)
5356 k=j<(MAXFFCS-1)?j+1:0;
5357
5358 if(prvscr.ffcs[j].flags&ffc_swapprev)
5359 k=j>0?j-1:(MAXFFCS-1);
5360
5361 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5362 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5363 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5364 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5365 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5366 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5367 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5368 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5369 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5370 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5371 }
5372 }
5373 }
5374 }
5375 }
5376 }
5377
5378 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5379 {
5380 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5381 {
5382 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5383 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5384 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5385 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5386 }
5387 else
5388 {
5389 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5390 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5391 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5392 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5393 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5394 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5395
5396 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5397 {
5398 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5399
5400 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5401
5402 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5403
5404 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5405 }
5406 }
5407 }
5408 else
5409 {
5410 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5411 prvscr.ffcs[i].delay--;
5412 }
5413
5414 if(prvscr.ffcs[i].x<-32)
5415 {
5416 if(prvscr.flags6&fWRAPAROUNDFF)
5417 {
5418 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5419 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5420 }
5421 else
5422 {
5423 prvscr.ffcs[i].data = 0;
5424 prvscr.ffcs[i].flags&=~ffc_carryover;
5425 }
5426 }
5427
5428 if(prvscr.ffcs[i].y<-32)
5429 {
5430 if(prvscr.flags6&fWRAPAROUNDFF)
5431 {
5432 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5433 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5434 }
5435 else
5436 {
5437 prvscr.ffcs[i].data = 0;
5438 prvscr.ffcs[i].flags&=~ffc_carryover;
5439 }
5440 }
5441
5442 if(prvscr.ffcs[i].x>=288)
5443 {
5444 if(prvscr.flags6&fWRAPAROUNDFF)
5445 {
5446 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5447 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5448 }
5449 else
5450 {
5451 prvscr.ffcs[i].data = 0;
5452 prvscr.ffcs[i].flags&=~ffc_carryover;
5453 }
5454 }
5455
5456 if(prvscr.ffcs[i].y>=208)
5457 {
5458 if(prvscr.flags6&fWRAPAROUNDFF)
5459 {
5460 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5461 ffprvy[i] = prvscr.ffcs[i].x.getZLong();
5462 }
5463 else
5464 {
5465 prvscr.ffcs[i].data = 0;
5466 prvscr.ffcs[i].flags&=~ffc_carryover;
5467 }
5468 }
5469
5470 }
5471 }
5472 }
5473
5474 void zmap::goto_dmapscr(int dmap, int scr)
5475 {
5476 setCurrMap(DMaps[dmap].map);
5477 setCurrScr(scr+DMaps[dmap].xoff);
5478 }
5479 void zmap::goto_mapscr(int map, int scr)
5480 {
5481 setCurrMap(map);
5482 setCurrScr(scr);
5483 }
5484
5485 void zmap::dowarp(int32_t type, int32_t index)
5486 {
5487 set_warpback();
5488 if(type==0)
5489 {
5490
5491 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5492 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5493
5494 switch(screens[cursor.screen].tilewarptype[index])
5495 {
5496 case wtCAVE:
5497 case wtNOWARP:
5498 break;
5499
5500 default:
5501 goto_dmapscr(dmap, scr);
5502 break;
5503 }
5504 }
5505 else if(type==1)
5506 {
5507 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5508 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5509
5510 switch(screens[cursor.screen].sidewarptype[index])
5511 {
5512 case wtCAVE:
5513 case wtNOWARP:
5514 break;
5515
5516 default:
5517 goto_dmapscr(dmap, scr);
5518 break;
5519 }
5520 }
5521 }
5522
5523 extern int32_t prv_twon;
5524
5525 void zmap::prv_dowarp(int32_t type, int32_t index)
5526 {
5527 if(type==0)
5528 {
5529
5530 int32_t dmap=prvscr.tilewarpdmap[index];
5531 int32_t scr=prvscr.tilewarpscr[index];
5532
5533 switch(prvscr.tilewarptype[index])
5534 {
5535 case wtCAVE:
5536 case wtNOWARP:
5537 break;
5538
5539 default:
5540 //setCurrMap(DMaps[dmap].map);
5541 //setCurrScr(scr+DMaps[dmap].xoff);
5542 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5543 loadlvlpal(getcolor());
5544 rebuild_trans_table();
5545 //prv_cmbcycle=0;
5546 break;
5547 }
5548 }
5549 else if(type==1)
5550 {
5551 int32_t dmap=prvscr.sidewarpdmap[index];
5552 int32_t scr=prvscr.sidewarpscr[index];
5553
5554 switch(prvscr.sidewarptype[index])
5555 {
5556 case wtCAVE:
5557 case wtNOWARP:
5558 break;
5559
5560 default:
5561 //setCurrMap(DMaps[dmap].map);
5562 //setCurrScr(scr+DMaps[dmap].xoff);
5563 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5564 loadlvlpal(getcolor());
5565 rebuild_trans_table();
5566 //prv_cmbcycle=0;
5567 break;
5568 }
5569 }
5570
5571 if(prv_twon)
5572 {
5573 prv_time=get_prvscr()->timedwarptics;
5574 }
5575
5576 //also reset FFC information (so that changers will work correctly) -DD
5577 memset(ffposx,0xFF,sizeof(int16_t)*32);
5578 memset(ffposy,0xFF,sizeof(int16_t)*32);
5579 memset(ffprvx,0xFF,sizeof(float)*32);
5580 memset(ffprvy,0xFF,sizeof(float)*32);
5581 }
5582
5583 void zmap::dowarp2(int32_t ring,int32_t index)
5584 {
5585 set_warpback();
5586 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5587 }
5588
5589 void zmap::set_warpback()
5590 {
5591 warpbackmap = cursor.map;
5592 warpbackscreen = cursor.screen;
5593 }
5594 bool zmap::has_warpback()
5595 {
5596 return warpbackmap && warpbackscreen
5597 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5598 }
5599 void zmap::warpback()
5600 {
5601 if(!has_warpback())
5602 return;
5603
5604 int m = cursor.map, s = cursor.screen;
5605 goto_mapscr(*warpbackmap, *warpbackscreen);
5606 warpbackmap = m;
5607 warpbackscreen = s;
5608 }
5609
5610 bool save_msgstrs(const char *path)
5611 {
5612 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5613
5614 if(!f)
5615 {
5616 return false;
5617 }
5618
5619 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5620 {
5621 pack_fclose(f);
5622 return true;
5623 }
5624
5625 pack_fclose(f);
5626 return false;
5627 }
5628
5629 1 bool save_strings_tsv(const char *path)
5630 {
5631 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5632
5633
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5634 {
5635 return false;
5636 }
5637
5638
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5639 {
5640 1 pack_fclose(f);
5641 1 return true;
5642 }
5643
5644 pack_fclose(f);
5645 return false;
5646 1 }
5647
5648 bool save_msgstrs_text(const char *path)
5649 {
5650 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5651
5652 if(!f)
5653 {
5654 return false;
5655 }
5656
5657 if(writestrings_text(f)==0)
5658 {
5659 pack_fclose(f);
5660 return true;
5661 }
5662
5663 pack_fclose(f);
5664 return false;
5665 }
5666
5667 bool load_msgstrs(const char *path, int32_t startstring)
5668 {
5669 //these are here to bypass compiler warnings about unused arguments
5670 startstring=startstring;
5671
5672 dword section_id;
5673 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5674
5675 if(!f)
5676 {
5677 return false;
5678 }
5679
5680 if(!p_mgetl(&section_id,f))
5681 {
5682 return false;
5683 }
5684
5685 if(section_id==ID_STRINGS)
5686 {
5687 if(readstrings(f, &header)==0)
5688 {
5689 pack_fclose(f);
5690 return true;
5691 }
5692 else
5693 {
5694 pack_fclose(f);
5695 return false;
5696 }
5697 }
5698
5699 pack_fclose(f);
5700 return false;
5701 }
5702
5703 bool load_strings_tsv(const char *path)
5704 {
5705 try
5706 {
5707 parse_strings_tsv(util::read_text_file(path));
5708 }
5709 catch (std::exception& ex)
5710 {
5711 InfoDialog("Import .tsv Error", ex.what()).show();
5712 return false;
5713 }
5714 return true;
5715 }
5716
5717 bool save_pals(const char *path)
5718 {
5719 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5720
5721 if(!f)
5722 {
5723 return false;
5724 }
5725
5726 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5727 {
5728 pack_fclose(f);
5729 return true;
5730 }
5731
5732 pack_fclose(f);
5733 return false;
5734 }
5735
5736 bool load_pals(const char *path, int32_t startcset)
5737 {
5738 dword section_id;
5739 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5740
5741 if(!f)
5742 {
5743 return false;
5744 }
5745
5746 if(!p_mgetl(&section_id,f))
5747 {
5748 return false;
5749 }
5750
5751 if(section_id==ID_CSETS)
5752 {
5753 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5754 {
5755 pack_fclose(f);
5756 loadlvlpal(Color);
5757 return true;
5758 }
5759 else
5760 {
5761 pack_fclose(f);
5762 return false;
5763 }
5764 }
5765
5766 return false;
5767 }
5768
5769 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5770 bool save_guys(const char *path)
5771 {
5772 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5773
5774 if(!f)
5775 {
5776 return false;
5777 }
5778
5779 /*
5780 int32_t id = ID_GUYS;
5781 if(!p_mputl(id,f))
5782 {
5783 return false;
5784 }
5785 */
5786
5787 zquestheader h;
5788 h.zelda_version = 0x250;
5789 h.build = 21;
5790
5791 if(writeguys(f, &h)==0)
5792 {
5793 pack_fclose(f);
5794 return true;
5795 }
5796
5797 pack_fclose(f);
5798 return false;
5799 }
5800
5801 bool load_guys(const char *path)
5802 {
5803 dword section_id;
5804 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5805
5806 if(!f)
5807 {
5808 return false;
5809 }
5810
5811 if(!p_mgetl(&section_id,f))
5812 {
5813 pack_fclose(f);
5814 return false;
5815 }
5816
5817 zquestheader h;
5818 h.zelda_version = 0x250;
5819 h.build = 21;
5820
5821 if(section_id==ID_GUYS)
5822 {
5823 if(readguys(f, &h)==0)
5824 {
5825 pack_fclose(f);
5826 return true;
5827 }
5828 }
5829
5830 pack_fclose(f);
5831 return false;
5832 }
5833
5834
5835 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5836 bool save_combo_alias(const char *path)
5837 {
5838 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5839
5840 if(!f)
5841 {
5842 return false;
5843 }
5844
5845 zquestheader h;
5846 h.zelda_version = 0x250;
5847 h.build = 21;
5848
5849 if(writecomboaliases(f, 0, 0)==0)
5850 {
5851 pack_fclose(f);
5852 return true;
5853 }
5854
5855 pack_fclose(f);
5856 return false;
5857 }
5858
5859 bool load_combo_alias(const char *path)
5860 {
5861 dword section_id;
5862 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5863
5864 if(!f)
5865 {
5866 return false;
5867 }
5868
5869 if(!p_mgetl(&section_id,f))
5870 {
5871 pack_fclose(f);
5872 return false;
5873 }
5874
5875 zquestheader h;
5876 h.zelda_version = 0x250;
5877 h.build = 21;
5878
5879 if(section_id==ID_COMBOALIASES)
5880 {
5881 if(readcomboaliases(f, &h, 0, 0)==0)
5882 {
5883 pack_fclose(f);
5884 return true;
5885 }
5886 }
5887
5888 pack_fclose(f);
5889 return false;
5890 }
5891
5892 bool load_zgp(const char *path)
5893 {
5894 dword section_id;
5895 dword section_version;
5896 dword section_cversion;
5897 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5898
5899 if(!f)
5900 return false;
5901
5902 if(!p_mgetl(&section_id,f))
5903 {
5904 pack_fclose(f);
5905 return false;
5906 }
5907
5908 if(section_id!=ID_GRAPHICSPACK)
5909 {
5910 pack_fclose(f);
5911 return false;
5912 }
5913
5914 //section version info
5915 if(!p_igetw(&section_version,f))
5916 {
5917 return 2;
5918 }
5919
5920 if(!p_igetw(&section_cversion,f))
5921 {
5922 return 3;
5923 }
5924
5925 //tiles
5926 if(!p_mgetl(&section_id,f))
5927 {
5928 pack_fclose(f);
5929 return false;
5930 }
5931
5932 if(section_id==ID_TILES)
5933 {
5934 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5935 {
5936 pack_fclose(f);
5937 init_tiles(true, &header);
5938 return false;
5939 }
5940 }
5941 else
5942 {
5943 pack_fclose(f);
5944 return false;
5945 }
5946
5947 //combos
5948 if(!p_mgetl(&section_id,f))
5949 {
5950 pack_fclose(f);
5951 return false;
5952 }
5953
5954 if(section_id==ID_COMBOS)
5955 {
5956 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5957 {
5958 pack_fclose(f);
5959 return false;
5960 }
5961 }
5962 else
5963 {
5964 pack_fclose(f);
5965 return false;
5966 }
5967
5968 //palettes
5969 if(!p_mgetl(&section_id,f))
5970 {
5971 pack_fclose(f);
5972 return false;
5973 }
5974
5975 if(section_id==ID_CSETS)
5976 {
5977 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5978 {
5979 pack_fclose(f);
5980 return false;
5981 }
5982 }
5983 else
5984 {
5985 pack_fclose(f);
5986 return false;
5987 }
5988
5989 //items
5990 if(!p_mgetl(&section_id,f))
5991 {
5992 pack_fclose(f);
5993 return false;
5994 }
5995
5996 if(section_id==ID_ITEMS)
5997 {
5998 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5999 {
6000 pack_fclose(f);
6001 return false;
6002 }
6003 }
6004 else
6005 {
6006 pack_fclose(f);
6007 return false;
6008 }
6009
6010 //weapons
6011 if(!p_mgetl(&section_id,f))
6012 {
6013 pack_fclose(f);
6014 return false;
6015 }
6016
6017 if(section_id==ID_WEAPONS)
6018 {
6019 if(readweapons(f, &header)!=0)
6020 {
6021 pack_fclose(f);
6022 return false;
6023 }
6024 }
6025 else
6026 {
6027 pack_fclose(f);
6028 return false;
6029 }
6030
6031 //read the triforce pieces info and make sure it worked
6032 //really do this?
6033
6034 //read the game icons info and make sure it worked
6035 if(!p_mgetl(&section_id,f))
6036 {
6037 pack_fclose(f);
6038 return false;
6039 }
6040
6041 if(section_id==ID_ICONS)
6042 {
6043 if(readgameicons(f, &header, &QMisc)!=0)
6044 {
6045 pack_fclose(f);
6046 return false;
6047 }
6048 }
6049 else
6050 {
6051 pack_fclose(f);
6052 return false;
6053 }
6054
6055 //read the misc colors info and map styles info and make sure it worked
6056 if(!p_mgetl(&section_id,f))
6057 {
6058 pack_fclose(f);
6059 return false;
6060 }
6061
6062 if(section_id==ID_COLORS)
6063 {
6064 if(readmisccolors(f, &header, &QMisc)!=0)
6065 {
6066 pack_fclose(f);
6067 return false;
6068 }
6069 }
6070 else
6071 {
6072 pack_fclose(f);
6073 return false;
6074 }
6075
6076 //read the door combo sets and make sure it worked
6077 if(!p_mgetl(&section_id,f))
6078 {
6079 pack_fclose(f);
6080 return false;
6081 }
6082
6083 if(section_id==ID_DOORS)
6084 {
6085 if(readdoorcombosets(f, &header)!=0)
6086 {
6087 pack_fclose(f);
6088 return false;
6089 }
6090 }
6091 else
6092 {
6093 pack_fclose(f);
6094 return false;
6095 }
6096
6097 //read the template screens and make sure it worked
6098 //really do this?
6099
6100 //yay! it worked! close the file and say everything was ok.
6101 loadlvlpal(Color);
6102 setup_combo_animations();
6103 setup_combo_animations2();
6104 pack_fclose(f);
6105 return true;
6106 }
6107
6108 bool save_zgp(const char *path)
6109 {
6110 reset_combo_animations();
6111 reset_combo_animations2();
6112
6113 //open the file
6114 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6115
6116 if(!f)
6117 return false;
6118
6119 dword section_id=ID_GRAPHICSPACK;
6120 dword section_version=V_GRAPHICSPACK;
6121 dword section_cversion=CV_GRAPHICSPACK;
6122
6123 //section id
6124 if(!p_mputl(section_id,f))
6125 {
6126 return 1;
6127 }
6128
6129 //section version info
6130 if(!p_iputw(section_version,f))
6131 {
6132 return 2;
6133 }
6134
6135 if(!p_iputw(section_cversion,f))
6136 {
6137 return 3;
6138 }
6139
6140 //tiles
6141 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6142 {
6143 pack_fclose(f);
6144 return false;
6145 }
6146
6147 //combos
6148 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6149 {
6150 pack_fclose(f);
6151 return false;
6152 }
6153
6154 //palettes
6155 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6156 {
6157 pack_fclose(f);
6158 return false;
6159 }
6160
6161 //items
6162 if(writeitems(f, &header)!=0)
6163 {
6164 pack_fclose(f);
6165 return false;
6166 }
6167
6168 //weapons
6169 if(writeweapons(f, &header)!=0)
6170 {
6171 pack_fclose(f);
6172 return false;
6173 }
6174
6175 //write the triforce pieces info and make sure it worked
6176 //really do this?
6177
6178 //write the game icons info and make sure it worked
6179 if(writegameicons(f, &header)!=0)
6180 {
6181 pack_fclose(f);
6182 return false;
6183 }
6184
6185 //write the misc colors info and map styles info and make sure it worked
6186 if(writemisccolors(f, &header)!=0)
6187 {
6188 pack_fclose(f);
6189 return false;
6190 }
6191
6192 //write the door combo sets and make sure it worked
6193 if(writedoorcombosets(f, &header)!=0)
6194 {
6195 pack_fclose(f);
6196 return false;
6197 }
6198
6199 //write the template screens and make sure it worked
6200 //really do this?
6201
6202 pack_fclose(f);
6203 return true;
6204 }
6205
6206 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6207 {
6208 //open the file
6209 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6210
6211 if(!f)
6212 return false;
6213
6214 dword section_id=ID_SUBSCREEN;
6215 dword s_version=V_SUBSCREEN;
6216 dword s_cversion=CV_SUBSCREEN;
6217
6218 if(!p_mputl(section_id,f))
6219 {
6220 pack_fclose(f);
6221 return false;
6222 }
6223
6224 if(!p_iputw(s_version,f))
6225 {
6226 pack_fclose(f);
6227 return false;
6228 }
6229
6230 if(!p_iputw(s_cversion,f))
6231 {
6232 pack_fclose(f);
6233 return false;
6234 }
6235
6236 if(savefrom.write(f))
6237 {
6238 pack_fclose(f);
6239 return false;
6240 }
6241
6242 pack_fclose(f);
6243 return true;
6244 }
6245
6246 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6247 {
6248 //open the file
6249 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6250
6251 if(!f)
6252 return false;
6253
6254 dword section_id;
6255 dword s_version;
6256 dword s_cversion;
6257
6258 if(!p_mgetl(&section_id,f))
6259 {
6260 pack_fclose(f);
6261 return false;
6262 }
6263
6264 if(section_id!=ID_SUBSCREEN)
6265 {
6266 pack_fclose(f);
6267 return false;
6268 }
6269
6270 if(!p_igetw(&s_version,f))
6271 {
6272 pack_fclose(f);
6273 return false;
6274 }
6275
6276 if(!p_igetw(&s_cversion,f))
6277 {
6278 pack_fclose(f);
6279 return false;
6280 }
6281
6282 if(s_version < 8)
6283 {
6284 subscreen_group g;
6285 memset(&g,0,sizeof(subscreen_group));
6286 if(read_one_old_subscreen(f,&g,s_version)!=0)
6287 {
6288 pack_fclose(f);
6289 return false;
6290 }
6291 if(g.ss_type != loadto.sub_type)
6292 {
6293 pack_fclose(f);
6294 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6295 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6296 return false;
6297 }
6298 loadto.clear();
6299 if(g.objects[0].type != ssoNULL)
6300 loadto.load_old(g);
6301 }
6302 else
6303 {
6304 ZCSubscreen tmp = ZCSubscreen();
6305 if (tmp.read(f, s_version))
6306 {
6307 pack_fclose(f);
6308 return false;
6309 }
6310 if(tmp.sub_type != loadto.sub_type)
6311 {
6312 pack_fclose(f);
6313 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6314 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6315 return false;
6316 }
6317 loadto.clear();
6318 loadto = tmp;
6319 }
6320
6321 pack_fclose(f);
6322 return true;
6323 }
6324
6325 bool setMapCount2(int32_t c)
6326 {
6327 int32_t oldmapcount=map_count;
6328 int32_t currmap=Map.getCurrMap();
6329
6330 bound(c,1,MAXMAPS);
6331 map_count=c;
6332
6333 try
6334 {
6335 TheMaps.resize(c*MAPSCRS);
6336 Map.force_refr_pointer();
6337 map_autolayers.resize(c*6);
6338 }
6339 catch(...)
6340 {
6341 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6342 return false;
6343 }
6344
6345 bound(currmap,0,c-1);
6346 if(map_count>oldmapcount)
6347 {
6348 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6349 {
6350 Map.setCurrMap(mc);
6351
6352 for(int32_t ms=0; ms<MAPSCRS; ms++)
6353 {
6354 Map.clearscr(ms);
6355 }
6356 }
6357 Map.setCurrMap(currmap);
6358 }
6359 else
6360 {
6361 Map.setCurrMap(currmap);
6362 if(!layers_valid(Map.CurrScr()))
6363 fix_layers(Map.CurrScr(), false);
6364
6365 for(int32_t i=0; i<MAXDMAPS; i++)
6366 {
6367 if(DMaps[i].map>=map_count)
6368 {
6369 DMaps[i].map=map_count-1;
6370 }
6371 }
6372 }
6373
6374 return true;
6375 }
6376
6377 extern BITMAP *bmap;
6378
6379 static bool loading_file_new = false;
6380 1 int32_t init_quest()
6381 {
6382 char qstdat_string[2048];
6383 1 strcpy(qstdat_string, "modules/classic/default.qst");
6384
6385 char buf[2048];
6386
6387 1 loading_file_new = true;
6388 1 load_quest(qstdat_string);
6389 1 loading_file_new = false;
6390
6391 1 sprintf(buf,"ZC Editor - Untitled Quest");
6392 1 set_window_title(buf);
6393 1 zinit.last_map = 0;
6394 1 zinit.last_screen = 0;
6395
6396
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(bmap != NULL)
6397 {
6398 destroy_bitmap(bmap);
6399 bmap=NULL;
6400 }
6401
6402 1 return 0;
6403 }
6404
6405 void set_questpwd(std::string_view pwd, bool use_keyfile)
6406 {
6407 header.use_keyfile=use_keyfile;
6408
6409 // string_view actually has some quirks that make it less than ideal here.
6410 // It'd probably be best to replace it, but this works for now.
6411 memset(header.password, 0, 256);
6412 strcpy(header.password, pwd.data());
6413 header.dirty_password=true;
6414
6415 cvs_MD5Context ctx;
6416 cvs_MD5Init(&ctx);
6417 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6418 cvs_MD5Final(header.pwd_hash, &ctx);
6419 }
6420
6421
6422 bool is_null_pwd_hash(uint8_t *pwd_hash)
6423 {
6424 cvs_MD5Context ctx;
6425 uint8_t md5sum[16];
6426 char pwd[2]="";
6427
6428 cvs_MD5Init(&ctx);
6429 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6430 cvs_MD5Final(md5sum, &ctx);
6431
6432 return (memcmp(md5sum,pwd_hash,16)==0);
6433 }
6434
6435 static DIALOG pwd_dlg[] =
6436 {
6437 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6438 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6439 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6440 // 2 (filename)
6441 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6442 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6443 // 4 (challenge hash)
6444 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6445 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6446 // 6 (password)
6447 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6448 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6449 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6450 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6451 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6452 };
6453
6454 int32_t reverse_string(char* str)
6455 {
6456
6457 if(NULL==str)
6458 {
6459 return -1; //no string
6460 }
6461
6462 int32_t l=(int32_t)strlen(str)-1; //get the string length
6463
6464 if(1==l)
6465 {
6466 return 1;
6467 }
6468
6469 char c;
6470
6471 for(int32_t x=0; x < l; x++,l--)
6472 {
6473 c = str[x];
6474 str[x] = str[l];
6475 str[l] = c;
6476 }
6477
6478 return 0;
6479 }
6480
6481 #ifdef __GNUC__
6482 #pragma GCC diagnostic push
6483 #pragma GCC diagnostic ignored "-Wunreachable-code"
6484 #endif
6485
6486 9 int32_t quest_access(const char *filename, zquestheader *hdr)
6487 {
6488
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (is_headless())
6489 9 return 1;
6490
6491 #ifdef __EMSCRIPTEN__
6492 return 1;
6493 #endif
6494
6495 //Protection against compiling a release version with password protection off.
6496 static bool passguard = false;
6497
6498 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6499 #define MUST_HAVE_PASSWORD
6500 passguard = true;
6501 #endif
6502
6503 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6504 #if (defined _MSC_VER || defined _NPASS)
6505 return 1;
6506 #endif
6507 #endif
6508 if(devpwd()) return 1;
6509
6510 char hash_string[33];
6511
6512 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6513 {
6514 return 1;
6515 }
6516
6517 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6518 return true;
6519
6520 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6521 pwd_dlg[2].dp=get_filename(filename);
6522 cvs_MD5Context ctx;
6523 uint8_t md5sum[16]={0};
6524 char response[33]="";
6525 char prompt[256]="";
6526
6527 memcpy(md5sum, hdr->pwd_hash, 16);
6528
6529 for(int32_t i=0; i<300; ++i)
6530 {
6531 for(int32_t j=0; j<16; ++j)
6532 {
6533 sprintf(response+j*2, "%02x", md5sum[j]);
6534 }
6535
6536 if(i&1)
6537 {
6538 reverse_string(response);
6539 }
6540
6541 if(i==149)
6542 {
6543 strcpy(hash_string, response);
6544 }
6545
6546 cvs_MD5Init(&ctx);
6547 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6548 cvs_MD5Final(md5sum, &ctx);
6549 }
6550
6551 pwd_dlg[4].dp=hash_string;
6552
6553 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6554 {
6555 sprintf(prompt,"%s",response);
6556 }
6557
6558 pwd_dlg[6].dp=prompt;
6559
6560 large_dialog(pwd_dlg);
6561
6562 int32_t cancel = do_zqdialog(pwd_dlg,6);
6563
6564 if(cancel == 8)
6565 return 2;
6566
6567 bool ret=check_questpwd(hdr, prompt);
6568
6569 if(!ret)
6570 {
6571 ret=(strcmp(response,prompt)==0);
6572 }
6573 return ret ? 1 : 0;
6574 9 }
6575
6576 void set_rules(byte* newrules);
6577 8 void popup_bugfix_dlg(const char* cfg)
6578 {
6579 8 bool dont_show_again = zc_get_config("zquest",cfg,0);
6580
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(!dont_show_again && hasCompatRulesEnabled())
6581 {
6582
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
24 AlertDialog("Apply New Bugfixes",
6583
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 "New bugfixes found that can be applied to this quest!"
6584 "\nWould you like to apply them?"
6585 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6586 8 [&](bool ret,bool dsa)
6587 {
6588 if(ret)
6589 {
6590 applyRuleTemplate(ruletemplateFixCompat);
6591 }
6592 if(dsa)
6593 {
6594 zc_set_config("zquest",cfg,1);
6595 }
6596 },
6597
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 "Yes","No",
6598 0,false, //timeout - none
6599 true //"Don't show this again"
6600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 ).show();
6601 8 }
6602 8 }
6603
6604 #ifdef __GNUC__
6605 #pragma GCC diagnostic pop
6606 #endif
6607
6608 // wrapper to reinitialize everything on an error
6609 9 int32_t load_quest(const char *filename, bool show_progress)
6610 {
6611 char buf[2048];
6612 // if(encrypted)
6613 // setPackfilePassword(datapwd);
6614 byte skip_flags[4];
6615
6616
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
45 for(int32_t i=0; i<4; ++i)
6617 {
6618 36 skip_flags[i]=0;
6619 36 }
6620
2/2
✓ Branch 0 taken 6228 times.
✓ Branch 1 taken 9 times.
6237 for(int32_t i=0; i<qr_MAX; i++)
6621 6228 set_qr(i,0);
6622 9 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags);
6623
6624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret!=qe_OK)
6625 {
6626 init_quest();
6627 }
6628 else
6629 {
6630 9 int32_t accessret = quest_access(filename, &header);
6631
6632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(accessret != 1)
6633 {
6634 init_quest();
6635
6636 if(accessret == 0)
6637 ret=qe_pwd;
6638 else
6639 ret=qe_cancel;
6640 }
6641 else
6642 {
6643 9 Map.clear();
6644 9 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6645 9 Map.setCurrScr(zinit.last_screen);
6646
6647
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string qst_cfg_header = qst_cfg_header_from_path(filepath);
6648
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 Map.setViewSize(zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1));
6649
6650 extern int32_t current_mappage;
6651 9 current_mappage = 0;
6652 9 bool found_default = false;
6653
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 65 times.
72 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6654 {
6655 65 auto &pg = map_page[q];
6656
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
65 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6657 {
6658 2 current_mappage = q;
6659 2 break;
6660 }
6661
4/8
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
63 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6662 56 continue;
6663 else
6664 {
6665 7 current_mappage = q;
6666 7 found_default = true;
6667 }
6668 7 }
6669
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 refresh(rALL);
6670
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 refresh_pal();
6671
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 set_rules(quest_rules);
6672 9 saved = true;
6673
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
9 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6674
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 popup_bugfix_dlg("dsa_compatrule");
6675
6676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(bmap != NULL)
6677 {
6678 destroy_bitmap(bmap);
6679 bmap=NULL;
6680 }
6681
6682
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if (show_progress)
6683 {
6684
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6685
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_window_title(buf);
6686 1 }
6687 9 }
6688 }
6689
6690 9 Map.ClearCommandHistory();
6691
6692
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (!is_headless())
6693 {
6694 void load_size_poses();
6695 load_size_poses();
6696 }
6697
6698 9 return ret;
6699 }
6700
6701 int32_t load_tileset(const char *filename, dword tsetflags)
6702 {
6703 char buf[2048];
6704 byte skip_flags[4];
6705
6706 for(int32_t i=0; i<4; ++i)
6707 skip_flags[i]=0;
6708 for(int32_t i=0; i<qr_MAX; i++)
6709 set_qr(i,0);
6710 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6711
6712 if(ret!=qe_OK)
6713 init_quest();
6714 else
6715 {
6716 int32_t accessret = quest_access(filename, &header);
6717
6718 if(accessret != 1)
6719 {
6720 init_quest();
6721
6722 if(accessret == 0)
6723 ret=qe_pwd;
6724 else
6725 ret=qe_cancel;
6726 }
6727 else
6728 {
6729 Map.clear();
6730 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6731 Map.setCurrScr(zinit.last_screen);
6732 extern int32_t current_mappage;
6733 current_mappage = 0;
6734 bool found_default = false;
6735 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6736 {
6737 auto &pg = map_page[q];
6738 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6739 {
6740 current_mappage = q;
6741 break;
6742 }
6743 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6744 continue;
6745 else
6746 {
6747 current_mappage = q;
6748 found_default = true;
6749 }
6750 }
6751 refresh(rALL);
6752 refresh_pal();
6753 set_rules(quest_rules);
6754 if(!zc_get_config("zquest","auto_filenew_bugfixes",1))
6755 popup_bugfix_dlg("dsa_compatrule");
6756
6757 if(bmap != NULL)
6758 {
6759 destroy_bitmap(bmap);
6760 bmap=NULL;
6761 }
6762
6763 set_window_title("ZC Editor - Untitled Quest");
6764 first_save = saved = false;
6765 memset(filepath,0,255);
6766 memset(temppath,0,255);
6767 }
6768 }
6769
6770 Map.ClearCommandHistory();
6771
6772 return ret;
6773 }
6774
6775 60 bool write_midi(MIDI *m,PACKFILE *f)
6776 {
6777 int32_t c;
6778
6779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 if(!p_mputw(m->divisions,f)) return false;
6780
6781
2/2
✓ Branch 0 taken 1920 times.
✓ Branch 1 taken 60 times.
1980 for(c=0; c<MIDI_TRACKS; c++)
6782 {
6783
1/2
✓ Branch 0 taken 1920 times.
✗ Branch 1 not taken.
1920 if(!p_mputl(m->track[c].len,f)) return false;
6784
6785
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 492 times.
1920 if(m->track[c].len > 0)
6786 {
6787
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6788 return false;
6789 492 }
6790 1920 }
6791
6792 60 return true;
6793 60 }
6794
6795 6 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6796 {
6797 6 dword section_id=ID_HEADER;
6798 6 dword section_version=V_HEADER;
6799 6 dword section_cversion=CV_HEADER;
6800 6 dword section_size=0;
6801
6802 //file header string
6803
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6804 {
6805 new_return(1);
6806 }
6807
6808 //section id
6809
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
6810 {
6811 new_return(2);
6812 }
6813
6814 //section version info
6815
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
6816 {
6817 new_return(3);
6818 }
6819
6820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
6821 {
6822 new_return(4);
6823 }
6824
6825
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6826 {
6827 12 fake_pack_writing=(writecycle==0);
6828
6829 //section size
6830
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
6831 {
6832 new_return(5);
6833 }
6834
6835 12 writesize=0;
6836
6837 //finally... section data
6838
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->zelda_version,f))
6839 {
6840 new_return(6);
6841 }
6842
6843
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->build,f))
6844 {
6845 new_return(7);
6846 }
6847
6848
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6849 {
6850 new_return(8);
6851 }
6852
6853
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->internal,f))
6854 {
6855 new_return(10);
6856 }
6857
6858
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->quest_number,f))
6859 {
6860 new_return(11);
6861 }
6862
6863
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->version,16,f))
6864 {
6865 new_return(12);
6866 }
6867
6868
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->minver,16,f))
6869 {
6870 new_return(13);
6871 }
6872
6873
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->title,sizeof(Header->title),f))
6874 {
6875 new_return(14);
6876 }
6877
6878
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->author,sizeof(Header->author),f))
6879 {
6880 new_return(15);
6881 }
6882
6883
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->use_keyfile,f))
6884 {
6885 new_return(16);
6886 }
6887
6888
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6889 {
6890 new_return(17);
6891 }
6892
6893
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6894 {
6895 new_return(19);
6896 }
6897
6898
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(0,f)) //why are we doing this?
6899 //this is for map count, it seems. -Z
6900 {
6901 new_return(20);
6902 }
6903
6904 12 auto version = getVersion();
6905
6906
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.major,f))
6907 {
6908 new_return(21);
6909 }
6910
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.minor,f))
6911 {
6912 new_return(22);
6913 }
6914
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.patch,f))
6915 {
6916 new_return(23);
6917 }
6918 // Fourth component is deprecated.
6919
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
6920 {
6921 new_return(24);
6922 }
6923
6924 // Numerous prerelease stages is deprecated.
6925
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
6926 {
6927 new_return(25);
6928 }
6929
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
6930 {
6931 new_return(26);
6932 }
6933
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
6934 {
6935 new_return(27);
6936 }
6937
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
6938 {
6939 new_return(28);
6940 }
6941
6942
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(BUILDTM_YEAR,f))
6943 {
6944 new_return(29);
6945 }
6946
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MONTH,f))
6947 {
6948 new_return(30);
6949 }
6950
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_DAY,f))
6951 {
6952 new_return(31);
6953 }
6954
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_HOUR,f))
6955 {
6956 new_return(32);
6957 }
6958
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MINUTE,f))
6959 {
6960 new_return(33);
6961 }
6962
6963
6964
6965 char tempsig[256];
6966 12 memset(tempsig, 0, 256);
6967 12 strcpy(tempsig, DEV_SIGNOFF);
6968
6969
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempsig,256,f))
6970 {
6971 new_return(34);
6972 }
6973
6974 char tempcompilersig[256];
6975 12 memset(tempcompilersig, 0, 256);
6976 12 strcpy(tempcompilersig, COMPILER_NAME);
6977
6978
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilersig,256,f))
6979 {
6980 new_return(35);
6981 }
6982
6983 char tempcompilerversion[256];
6984 12 memset(tempcompilerversion, 0, 256);
6985 #ifdef _MSC_VER
6986 zc_itoa(_MSC_VER,tempcompilerversion,10);
6987 #else
6988 12 strcpy(tempcompilerversion, COMPILER_VERSION);
6989 #endif
6990
6991
6992
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilerversion,256,f))
6993 {
6994 new_return(36);
6995 }
6996
6997
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite("ZQuest Classic",1024,f))
6998 {
6999 new_return(37);
7000 }
7001
7002
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(V_ZC_COMPILERSIG,f))
7003 {
7004 new_return(38);
7005 }
7006 #ifdef _MSC_VER
7007 if(!p_iputl((_MSC_VER / 100),f))
7008 {
7009 new_return(39);
7010 }
7011 #else
7012
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FIRST,f))
7013 {
7014 new_return(39);
7015 }
7016 #endif
7017
7018
7019
7020 #ifdef _MSC_VER
7021 if(!p_iputl((_MSC_VER % 100),f))
7022 {
7023 new_return(41);
7024 }
7025 #else
7026
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_SECOND,f))
7027 {
7028 new_return(41);
7029 }
7030 #endif
7031
7032 #ifdef _MSC_VER
7033 # if _MSC_VER >= 1400
7034 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7035 {
7036 new_return(40);
7037 }
7038 # else
7039 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7040 {
7041 new_return(40);
7042 }
7043 #endif
7044 #else
7045
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_THIRD,f))
7046 {
7047 new_return(40);
7048 }
7049 #endif
7050
7051 #ifdef _MSC_VER
7052 if(!p_iputl((_MSC_BUILD),f))
7053 {
7054 new_return(42);
7055 }
7056 #else
7057
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FOURTH,f))
7058 {
7059 new_return(42);
7060 }
7061 #endif
7062
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7063 {
7064 new_return(43);
7065 }
7066
7067 char tempmodulename[1024];
7068 12 memset(tempmodulename, 0, 1024);
7069 12 strcpy(tempmodulename, moduledata.module_name);
7070
7071
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempmodulename,1024,f))
7072 {
7073 new_return(44);
7074 }
7075
7076 char tempdate[256];
7077 12 memset(tempdate, 0, 256);
7078 12 strcpy(tempdate, __DATE__);
7079
7080
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempdate,256,f))
7081 {
7082 new_return(45);
7083 }
7084 char temptime[256];
7085 12 memset(temptime, 0, 256);
7086 12 strcpy(temptime, __TIME__);
7087
7088
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptime,256,f))
7089 {
7090 new_return(46);
7091 }
7092
7093
7094 char temptimezone[6];
7095 12 memset(temptimezone, 0, 6);
7096 12 strcpy(temptimezone, __TIMEZONE__);
7097
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptimezone,6,f))
7098 {
7099 new_return(47);
7100 }
7101
7102
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7103 {
7104 new_return(48);
7105 }
7106
7107
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(isStableRelease() ? 0 : 1, f))
7108 {
7109 new_return(49);
7110 }
7111
7112
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 if(!p_putcstr(version.version_string, f))
7113 {
7114 new_return(50);
7115 }
7116
7117
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7118 {
7119 6 section_size=writesize;
7120 6 }
7121 12 }
7122
7123
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7124 {
7125 char ebuf[80];
7126 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7127 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7128 }
7129
7130 6 new_return(0);
7131 }
7132
7133 6 int32_t writerules(PACKFILE *f, zquestheader *Header)
7134 {
7135 //these are here to bypass compiler warnings about unused arguments
7136 6 Header=Header;
7137
7138 6 dword section_id=ID_RULES;
7139 6 dword section_version=V_RULES;
7140 6 dword section_cversion=CV_RULES;
7141 6 dword section_size=0;
7142
7143 //section id
7144
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7145 {
7146 new_return(1);
7147 }
7148
7149 //section version info
7150
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7151 {
7152 new_return(2);
7153 }
7154
7155
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
7156 {
7157 new_return(3);
7158 }
7159
7160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl(V_COMPATRULE,f))
7161 {
7162 new_return(6);
7163 }
7164
7165
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7166 {
7167 12 fake_pack_writing=(writecycle==0);
7168
7169 //section size
7170
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7171 {
7172 new_return(4);
7173 }
7174
7175 12 writesize=0;
7176
7177 //finally... section data
7178
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7179 {
7180 new_return(5);
7181 }
7182
7183
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7184 {
7185 6 section_size=writesize;
7186 6 }
7187 12 }
7188
7189
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7190 {
7191 char ebuf[80];
7192 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7193 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7194 }
7195
7196 6 new_return(0);
7197 }
7198
7199
7200 6 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7201 {
7202 //these are here to bypass compiler warnings about unused arguments
7203 6 Header=Header;
7204
7205 6 dword section_id=ID_DOORS;
7206 6 dword section_version=V_DOORS;
7207 6 dword section_cversion=CV_DOORS;
7208 6 dword section_size=0;
7209
7210 //section id
7211
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7212 {
7213 new_return(1);
7214 }
7215
7216 //section version info
7217
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7218 {
7219 new_return(2);
7220 }
7221
7222
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7223 {
7224 new_return(3);
7225 }
7226
7227
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7228 {
7229 12 fake_pack_writing=(writecycle==0);
7230
7231 //section size
7232
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7233 {
7234 new_return(4);
7235 }
7236
7237 12 writesize=0;
7238
7239 //finally... section data
7240
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(door_combo_set_count,f))
7241 {
7242 new_return(5);
7243 }
7244
7245
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 12 times.
176 for(int32_t i=0; i<door_combo_set_count; i++)
7246 {
7247 //name
7248
1/2
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
164 if(!pfwrite(&DoorComboSets[i].name,sizeof(DoorComboSets[0].name),f))
7249 {
7250 new_return(6);
7251 }
7252
7253 //up door
7254
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7255 {
7256
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7257 {
7258
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7259 {
7260 new_return(7);
7261 }
7262 5904 }
7263 1476 }
7264
7265
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7266 {
7267
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7268 {
7269
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7270 {
7271 new_return(8);
7272 }
7273 5904 }
7274 1476 }
7275
7276 //down door
7277
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7278 {
7279
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7280 {
7281
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7282 {
7283 new_return(9);
7284 }
7285 5904 }
7286 1476 }
7287
7288
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7289 {
7290
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7291 {
7292
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7293 {
7294 new_return(10);
7295 }
7296 5904 }
7297 1476 }
7298
7299
7300 //left door
7301
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7302 {
7303
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7304 {
7305
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7306
7307 {
7308 new_return(11);
7309 }
7310 8856 }
7311 1476 }
7312
7313
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7314 {
7315
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7316 {
7317
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7318 {
7319 new_return(12);
7320 }
7321 8856 }
7322 1476 }
7323
7324 //right door
7325
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7326 {
7327
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7328 {
7329
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7330 {
7331 new_return(13);
7332 }
7333 8856 }
7334 1476 }
7335
7336
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7337 {
7338
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7339 {
7340
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7341 {
7342 new_return(14);
7343 }
7344 8856 }
7345 1476 }
7346
7347
7348 //up bomb rubble
7349
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7350 {
7351
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7352 {
7353 new_return(15);
7354 }
7355 328 }
7356
7357
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7358 {
7359
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7360 {
7361 new_return(16);
7362 }
7363 328 }
7364
7365 //down bomb rubble
7366
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7367 {
7368
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7369 {
7370 new_return(17);
7371 }
7372 328 }
7373
7374
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7375 {
7376
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7377 {
7378 new_return(18);
7379 }
7380 328 }
7381
7382 //left bomb rubble
7383
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7384 {
7385
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7386 {
7387 new_return(19);
7388 }
7389 492 }
7390
7391
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7392 {
7393
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7394 {
7395 new_return(20);
7396 }
7397 492 }
7398
7399 //right bomb rubble
7400
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7401 {
7402
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7403 {
7404 new_return(21);
7405 }
7406 492 }
7407
7408
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7409 {
7410
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7411 {
7412 new_return(22);
7413 }
7414 492 }
7415
7416 //walkthrough stuff
7417
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7418 {
7419
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7420 {
7421 new_return(23);
7422 }
7423 656 }
7424
7425
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7426 {
7427
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7428 {
7429 new_return(24);
7430 }
7431 656 }
7432
7433 //flags
7434
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7435 {
7436
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].flags[j],f))
7437 {
7438 new_return(25);
7439 }
7440 328 }
7441 164 }
7442
7443
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7444 {
7445 6 section_size=writesize;
7446 6 }
7447 12 }
7448
7449
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7450 {
7451 char ebuf[80];
7452 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7453 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7454 }
7455
7456 6 new_return(0);
7457 }
7458
7459 6 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7460 {
7461 //these are here to bypass compiler warnings about unused arguments
7462 6 version=version;
7463 6 build=build;
7464
7465 6 word dmap_count=count_dmaps();
7466 6 dword section_id=ID_DMAPS;
7467 6 dword section_version=V_DMAPS;
7468 6 dword section_cversion=CV_DMAPS;
7469 6 dword section_size=0;
7470
7471 //section id
7472
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7473 {
7474 new_return(1);
7475 }
7476
7477 //section version info
7478
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7479 {
7480 new_return(2);
7481 }
7482
7483
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7484 {
7485 new_return(3);
7486 }
7487
7488
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7489 {
7490 12 fake_pack_writing=(writecycle==0);
7491
7492 //section size
7493
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7494 {
7495 new_return(4);
7496 }
7497
7498 12 writesize=0;
7499
7500
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, max_dmaps);
7501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7502
7503 //finally... section data
7504
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(dmap_count,f))
7505 {
7506 new_return(5);
7507 }
7508
7509
7510
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7511 {
7512 6144 DMaps[i].validate_subscreens();
7513
7514
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].map,f))
7515 {
7516 new_return(6);
7517 }
7518
7519
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].level,f))
7520 {
7521 new_return(7);
7522 }
7523
7524
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].xoff,f))
7525 {
7526 new_return(8);
7527 }
7528
7529
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].compass,f))
7530 {
7531 new_return(9);
7532 }
7533
7534
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].color,f))
7535 {
7536 new_return(10);
7537 }
7538
7539
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].midi,f))
7540 {
7541 new_return(11);
7542 }
7543
7544
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].cont,f))
7545 {
7546 new_return(12);
7547 }
7548
7549
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].type,f))
7550 {
7551 new_return(13);
7552 }
7553
7554
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7555 {
7556
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(DMaps[i].grid[j],f))
7557 {
7558 new_return(14);
7559 }
7560 49152 }
7561
7562
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7563 {
7564 new_return(15);
7565 }
7566
7567
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putwstr(DMaps[i].title,f))
7568 {
7569 new_return(16);
7570 }
7571
7572
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7573 {
7574 new_return(17);
7575 }
7576
7577
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_1_tile,f))
7578 {
7579 new_return(18);
7580 }
7581
7582
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_1_cset,f))
7583 {
7584 new_return(19);
7585 }
7586
7587
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_2_tile,f))
7588 {
7589 new_return(20);
7590 }
7591
7592
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_2_cset,f))
7593 {
7594 new_return(21);
7595 }
7596
7597
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_1_tile,f))
7598 {
7599 new_return(22);
7600 }
7601
7602
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_1_cset,f))
7603 {
7604 new_return(23);
7605 }
7606
7607
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_2_tile,f))
7608 {
7609 new_return(24);
7610 }
7611
7612
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_2_cset,f))
7613 {
7614 new_return(25);
7615 }
7616
7617
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7618 {
7619 new_return(26);
7620 }
7621
7622
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].tmusictrack,f))
7623 {
7624 new_return(25);
7625 }
7626
7627
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].active_subscreen,f))
7628 {
7629 new_return(26);
7630 }
7631
7632
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].passive_subscreen,f))
7633 {
7634 new_return(27);
7635 }
7636
7637 byte disabled[32];
7638 6144 memset(disabled,0,32);
7639
7640
2/2
✓ Branch 0 taken 1572864 times.
✓ Branch 1 taken 6144 times.
1579008 for(int32_t j=0; j<MAXITEMS; j++)
7641 {
7642
1/2
✓ Branch 0 taken 1572864 times.
✗ Branch 1 not taken.
1572864 if(DMaps[i].disableditems[j])
7643 {
7644 disabled[j/8] |= (1 << (j%8));
7645 }
7646 1572864 }
7647
7648
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(disabled,32,f))
7649 {
7650 new_return(28);
7651 }
7652
7653
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].flags,f))
7654 {
7655 new_return(29);
7656 }
7657
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].sideview,f))
7658 {
7659 new_return(30);
7660 }
7661
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].script,f))
7662 {
7663 new_return(31);
7664 }
7665
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7666 {
7667
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].initD[q],f))
7668 {
7669 new_return(32);
7670 }
7671
7672 49152 }
7673
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7674 {
7675
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
7676 {
7677
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if (!p_putc(DMaps[i].initD_label[q][w],f))
7678 {
7679 new_return(33);
7680 }
7681 3194880 }
7682 49152 }
7683
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].active_sub_script,f))
7684 {
7685 new_return(34);
7686 }
7687
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].passive_sub_script,f))
7688 {
7689 new_return(35);
7690 }
7691
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7692 {
7693
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].sub_initD[q],f))
7694 {
7695 new_return(36);
7696 }
7697 49152 }
7698
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7699 {
7700
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7701 {
7702
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7703 {
7704 new_return(37);
7705 }
7706 3194880 }
7707 49152 }
7708
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].onmap_script,f))
7709 {
7710 new_return(38);
7711 }
7712
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7713 {
7714
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7715 {
7716 new_return(39);
7717 }
7718 49152 }
7719
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7720 {
7721
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7722 {
7723
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7724 {
7725 new_return(40);
7726 }
7727 3194880 }
7728 49152 }
7729
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].mirrorDMap,f))
7730 {
7731 new_return(41);
7732 }
7733
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7734 {
7735 new_return(42);
7736 }
7737
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7738 {
7739 new_return(43);
7740 }
7741
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7742 {
7743 new_return(44);
7744 }
7745
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7746 {
7747 new_return(45);
7748 }
7749
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].overlay_subscreen, f))
7750 new_return(46);
7751
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].intro_string_id, f))
7752 new_return(47);
7753
7754 // Reserved for z3.
7755
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7756 {
7757
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 393216 times.
442368 for(int32_t k=0; k<8; k++)
7758 {
7759
1/2
✓ Branch 0 taken 393216 times.
✗ Branch 1 not taken.
393216 if(!p_putc(0,f))
7760 {
7761 new_return(48);
7762 }
7763 393216 }
7764 49152 }
7765 6144 }
7766
7767
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7768 {
7769 6 section_size=writesize;
7770 6 }
7771 12 }
7772
7773
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7774 {
7775 char ebuf[80];
7776 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7777 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7778 }
7779
7780 6 new_return(0);
7781 }
7782
7783 6 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7784 {
7785 //these are here to bypass compiler warnings about unused arguments
7786 6 Header=Header;
7787
7788 6 dword section_id=ID_COLORS;
7789 6 dword section_version=V_COLORS;
7790 6 dword section_cversion=CV_COLORS;
7791 6 dword section_size = 0;
7792
7793 //section id
7794
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7795 {
7796 new_return(1);
7797 }
7798
7799
7800 //section version info
7801
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7802 {
7803 new_return(2);
7804 }
7805
7806
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7807 {
7808 new_return(3);
7809 }
7810
7811
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7812 {
7813 12 fake_pack_writing=(writecycle==0);
7814
7815 //section size
7816
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7817 {
7818 new_return(4);
7819 }
7820
7821 12 writesize=0;
7822
7823
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.text,f))
7824 {
7825 new_return(5);
7826 }
7827
7828
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.caption,f))
7829 {
7830 new_return(6);
7831 }
7832
7833
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overw_bg,f))
7834 {
7835 new_return(7);
7836 }
7837
7838
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_bg,f))
7839 {
7840 new_return(8);
7841 }
7842
7843
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_fg,f))
7844 {
7845 new_return(9);
7846 }
7847
7848
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.cave_fg,f))
7849 {
7850 new_return(10);
7851 }
7852
7853
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_dk,f))
7854 {
7855 new_return(11);
7856 }
7857
7858
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_goal,f))
7859 {
7860 new_return(12);
7861 }
7862
7863
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_lt,f))
7864 {
7865 new_return(13);
7866 }
7867
7868
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_dk,f))
7869 {
7870 new_return(14);
7871 }
7872
7873
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_bg,f))
7874 {
7875 new_return(15);
7876 }
7877
7878
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_color,f))
7879 {
7880 new_return(16);
7881 }
7882
7883
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.hero_dot,f))
7884 {
7885 new_return(17);
7886 }
7887
7888
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_bg,f))
7889 {
7890 new_return(18);
7891 }
7892
7893
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_fg,f))
7894 {
7895 new_return(19);
7896 }
7897
7898
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triforce_cset,f))
7899 {
7900 new_return(20);
7901 }
7902
7903
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_cset,f))
7904 {
7905 new_return(21);
7906 }
7907
7908
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7909 {
7910 new_return(22);
7911 }
7912
7913
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7914 {
7915 new_return(23);
7916 }
7917
7918
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.blueframe_cset,f))
7919 {
7920 new_return(24);
7921 }
7922
7923
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7924 {
7925 new_return(31);
7926 }
7927
7928
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_shadow,f))
7929 {
7930 new_return(32);
7931 }
7932
7933
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.msgtext,f))
7934 {
7935 new_return(33);
7936 }
7937
7938
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triforce_tile,f))
7939 {
7940 new_return(34);
7941 }
7942
7943
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triframe_tile,f))
7944 {
7945 new_return(35);
7946 }
7947
7948
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7949 {
7950 new_return(36);
7951 }
7952
7953
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7954 {
7955 new_return(37);
7956 }
7957
7958
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7959 {
7960 new_return(38);
7961 }
7962
7963
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7964 {
7965 new_return(39);
7966 }
7967
7968
7969
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7970 {
7971 6 section_size=writesize;
7972 6 }
7973 12 }
7974
7975
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7976 {
7977 char ebuf[80];
7978 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7979 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7980 }
7981
7982 6 new_return(0);
7983 }
7984
7985 6 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7986 {
7987 //these are here to bypass compiler warnings about unused arguments
7988 6 Header=Header;
7989
7990 6 dword section_id=ID_ICONS;
7991 6 dword section_version=V_ICONS;
7992 6 dword section_cversion=CV_ICONS;
7993 6 dword section_size = 0;
7994
7995 //section id
7996
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7997 {
7998 new_return(1);
7999 }
8000
8001 //section version info
8002
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8003 {
8004 new_return(2);
8005 }
8006
8007
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8008 {
8009 new_return(3);
8010 }
8011
8012
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8013 {
8014 12 fake_pack_writing=(writecycle==0);
8015
8016 //section size
8017
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8018 {
8019 new_return(4);
8020 }
8021
8022 12 writesize=0;
8023
8024
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
8025 {
8026
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(QMisc.icons[i],f))
8027 {
8028 new_return(5);
8029 }
8030 48 }
8031
8032
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8033 {
8034 6 section_size=writesize;
8035 6 }
8036 12 }
8037
8038
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8039 {
8040 char ebuf[80];
8041 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8042 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8043 }
8044
8045 6 new_return(0);
8046 }
8047
8048 6 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8049 {
8050 //these are here to bypass compiler warnings about unused arguments
8051 6 Header=Header;
8052
8053 6 dword section_id=ID_MISC;
8054 6 dword section_version=V_MISC;
8055 6 dword section_cversion=CV_MISC;
8056 6 word shops=count_shops(&QMisc);
8057 6 word infos=count_infos(&QMisc);
8058 6 word warprings=count_warprings(&QMisc);
8059 6 word triforces=8;
8060 6 dword section_size = 0;
8061
8062 //section id
8063
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8064 {
8065 new_return(1);
8066 }
8067
8068
8069 //section version info
8070
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8071 {
8072 new_return(2);
8073 }
8074
8075
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8076 {
8077 new_return(3);
8078 }
8079
8080
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8081 {
8082 12 fake_pack_writing=(writecycle==0);
8083
8084 //section size
8085
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8086 {
8087 new_return(4);
8088 }
8089
8090 12 writesize=0;
8091
8092 //shops
8093
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(shops,f))
8094 {
8095 new_return(5);
8096 }
8097
8098
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8099 {
8100
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8101 {
8102 new_return(6);
8103 }
8104
8105
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8106 {
8107
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].item[j],f))
8108 {
8109 new_return(7);
8110 }
8111 384 }
8112
8113
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8114 {
8115
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].price[j],f))
8116 {
8117 new_return(8);
8118 }
8119 384 }
8120
8121
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8122 {
8123
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8124 {
8125 new_return(9);
8126 }
8127 384 }
8128 128 }
8129
8130 //infos
8131
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(infos,f))
8132 {
8133 new_return(10);
8134 }
8135
8136
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<infos; i++)
8137 {
8138
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8139 {
8140 new_return(11);
8141 }
8142
8143
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8144 {
8145
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].str[j],f))
8146 {
8147 new_return(12);
8148 }
8149 384 }
8150
8151
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8152 {
8153
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].price[j],f))
8154 {
8155 new_return(13);
8156 }
8157 384 }
8158 128 }
8159
8160 //warp rings
8161
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(warprings,f))
8162 {
8163 new_return(14);
8164 }
8165
8166
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 12 times.
156 for(int32_t i=0; i<warprings; i++)
8167 {
8168
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8169 {
8170
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8171 {
8172 new_return(15);
8173 }
8174 1296 }
8175
8176
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8177 {
8178
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_putc(QMisc.warp[i].scr[j],f))
8179 {
8180 new_return(16);
8181 }
8182 1296 }
8183
8184
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.warp[i].size,f))
8185 {
8186 new_return(17);
8187 }
8188 144 }
8189
8190 //triforce pieces
8191
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<triforces; i++)
8192 {
8193
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(!p_putc(QMisc.triforce[i],f))
8194 {
8195 new_return(18);
8196 }
8197 96 }
8198
8199 //end string
8200
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(QMisc.endstring,f))
8201 {
8202 new_return(19);
8203 }
8204
8205 //V_MISC >= 8
8206
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8207 {
8208
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8209 {
8210
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].str[j],f))
8211 {
8212 new_return(20);
8213 }
8214 384 }
8215 128 }
8216 //V_MISC >= 9
8217
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8218 {
8219
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputl(QMisc.questmisc[q],f))
8220 new_return(21);
8221 384 }
8222
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8223 {
8224
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 384 times.
49536 for ( int32_t j = 0; j < 128; j++ )
8225
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(0,f))
8226 new_return(22);
8227 384 }
8228 //V_MISC >= 11
8229
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8230 new_return(23);
8231
8232 //V_MISC >= 12
8233
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sprMAX; ++q)
8234 {
8235
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.sprites[q],f))
8236 new_return(24);
8237 3072 }
8238
8239 //V_MISC >= 13
8240
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(size_t q = 0; q < 64; ++q)
8241 {
8242 768 bottletype* bt = &(QMisc.bottle_types[q]);
8243
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!pfwrite(bt->name, 32, f))
8244 new_return(25);
8245
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 768 times.
3072 for(size_t j = 0; j < 3; ++j)
8246 {
8247
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_putc(bt->counter[j], f))
8248 new_return(25);
8249
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_iputw(bt->amount[j], f))
8250 new_return(25);
8251 2304 }
8252
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->flags, f))
8253 new_return(25);
8254
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->next_type, f))
8255 new_return(25);
8256 768 }
8257
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(size_t q = 0; q < 256; ++q)
8258 {
8259 3072 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8260
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if (!pfwrite(bst->name, 32, f))
8261 new_return(26);
8262
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 3072 times.
12288 for(size_t j = 0; j < 3; ++j)
8263 {
8264
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->fill[j], f))
8265 new_return(26);
8266
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->comb[j], f))
8267 new_return(26);
8268
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->cset[j], f))
8269 new_return(26);
8270
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->price[j], f))
8271 new_return(26);
8272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (!p_iputw(bst->str[j], f))
8273 new_return(26);
8274 9216 }
8275 3072 }
8276
8277 //V_MISC >= 14
8278
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sfxMAX; ++q)
8279 {
8280
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.miscsfx[q],f))
8281 new_return(27);
8282 3072 }
8283
8284
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8285 {
8286 6 section_size=writesize;
8287 6 }
8288 12 }
8289
8290
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8291 {
8292 char ebuf[80];
8293 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8294 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8295 }
8296
8297 6 new_return(0);
8298 }
8299
8300 6 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8301 {
8302 //these are here to bypass compiler warnings about unused arguments
8303 6 Header=Header;
8304
8305 6 dword section_id=ID_ITEMS;
8306 6 dword section_version=V_ITEMS;
8307 6 dword section_cversion=CV_ITEMS;
8308 // dword section_size=0;
8309 6 dword section_size = 0;
8310
8311 //section id
8312
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8313 {
8314 new_return(1);
8315 }
8316
8317 //section version info
8318
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8319 {
8320 new_return(2);
8321 }
8322
8323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8324 {
8325 new_return(3);
8326 }
8327
8328
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8329 {
8330 12 fake_pack_writing=(writecycle==0);
8331
8332 //section size
8333
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8334 {
8335 new_return(4);
8336 }
8337
8338 12 writesize=0;
8339
8340 //finally... section data
8341
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXITEMS,f))
8342 {
8343 new_return(5);
8344 }
8345
8346
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8347 {
8348
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite(item_string[i], 64, f))
8349 {
8350 new_return(5);
8351 }
8352 3072 }
8353
8354
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8355 {
8356
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tile,f))
8357 {
8358 new_return(6);
8359 }
8360
8361
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].misc_flags,f))
8362 {
8363 new_return(7);
8364 }
8365
8366
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].csets,f))
8367 {
8368 new_return(8);
8369 }
8370
8371
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].frames,f))
8372 {
8373 new_return(9);
8374 }
8375
8376
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].speed,f))
8377 {
8378 new_return(10);
8379 }
8380
8381
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].delay,f))
8382 {
8383 new_return(11);
8384 }
8385
8386
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].ltm,f))
8387 {
8388 new_return(12);
8389 }
8390
8391
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].family,f))
8392 {
8393 new_return(13);
8394 }
8395
8396
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].fam_type,f))
8397 {
8398 new_return(14);
8399 }
8400
8401
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].power,f))
8402 {
8403 new_return(14);
8404 }
8405
8406
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].flags,f))
8407 {
8408 new_return(15);
8409 }
8410
8411
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].script,f))
8412 {
8413 new_return(16);
8414 }
8415
8416
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].count,f))
8417 {
8418 new_return(17);
8419 }
8420
8421
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].amount,f))
8422 {
8423 new_return(18);
8424 }
8425
8426
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].collect_script,f))
8427 {
8428 new_return(19);
8429 }
8430
8431
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].setmax,f))
8432 {
8433 new_return(21);
8434 }
8435
8436
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].max,f))
8437 {
8438 new_return(22);
8439 }
8440
8441
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].playsound,f))
8442 {
8443 new_return(23);
8444 }
8445
8446
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for(int32_t j=0; j<8; j++)
8447 {
8448
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].initiald[j],f))
8449 {
8450 new_return(24);
8451 }
8452 24576 }
8453
8454
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(int32_t j=0; j<2; j++)
8455 {
8456
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].initiala[j],f))
8457 {
8458 new_return(25);
8459 }
8460 6144 }
8461
8462
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn,f))
8463 {
8464 new_return(26);
8465 }
8466
8467
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn2,f))
8468 {
8469 new_return(27);
8470 }
8471
8472
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn3,f))
8473 {
8474 new_return(28);
8475 }
8476
8477
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn4,f))
8478 {
8479 new_return(29);
8480 }
8481
8482
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn5,f))
8483 {
8484 new_return(30);
8485 }
8486
8487
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn6,f))
8488 {
8489 new_return(31);
8490 }
8491
8492
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn7,f))
8493 {
8494 new_return(32);
8495 }
8496
8497
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn8,f))
8498 {
8499 new_return(33);
8500 }
8501
8502
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn9,f))
8503 {
8504 new_return(34);
8505 }
8506
8507
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn10,f))
8508 {
8509 new_return(35);
8510 }
8511
8512
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8513 {
8514 new_return(36);
8515 }
8516
8517
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc1,f))
8518 {
8519 new_return(37);
8520 }
8521
8522
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc2,f))
8523 {
8524 new_return(38);
8525 }
8526
8527
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8528 {
8529
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8530 {
8531 new_return(39);
8532 }
8533 6144 }
8534
8535
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc3,f))
8536 {
8537 new_return(40);
8538 }
8539
8540
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc4,f))
8541 {
8542 new_return(41);
8543 }
8544
8545
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc5,f))
8546 {
8547 new_return(42);
8548 }
8549
8550
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc6,f))
8551 {
8552 new_return(43);
8553 }
8554
8555
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc7,f))
8556 {
8557 new_return(44);
8558 }
8559
8560
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc8,f))
8561 {
8562 new_return(45);
8563 }
8564
8565
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc9,f))
8566 {
8567 new_return(46);
8568 }
8569
8570
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc10,f))
8571 {
8572 new_return(47);
8573 }
8574
8575
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound,f))
8576 {
8577 new_return(48);
8578 }
8579
8580
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound2,f))
8581 {
8582 new_return(48);
8583 }
8584
8585 //New itemdata vars -Z
8586 //! version 27
8587
8588
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].useweapon,f))
8589 {
8590 new_return(49);
8591 }
8592
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usedefence,f))
8593 {
8594 new_return(50);
8595 }
8596
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weaprange,f))
8597 {
8598 new_return(51);
8599 }
8600
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapduration,f))
8601 {
8602 new_return(52);
8603 }
8604
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 3072 times.
33792 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8605
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8606 {
8607 new_return(53);
8608 }
8609 30720 }
8610 //version 28
8611
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].duplicates,f))
8612 {
8613 new_return(54);
8614 }
8615
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < INITIAL_D; q++ )
8616 {
8617
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
8618 {
8619 new_return(55);
8620 }
8621 24576 }
8622
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < INITIAL_A; q++ )
8623 {
8624
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].weap_initiala[q],f))
8625 {
8626 new_return(56);
8627 }
8628 6144 }
8629
8630
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].drawlayer,f))
8631 {
8632 new_return(57);
8633 }
8634
8635
8636
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxofs,f))
8637 {
8638 new_return(58);
8639 }
8640
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hyofs,f))
8641 {
8642 new_return(59);
8643 }
8644
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxsz,f))
8645 {
8646 new_return(60);
8647 }
8648
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hysz,f))
8649 {
8650 new_return(61);
8651 }
8652
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hzsz,f))
8653 {
8654 new_return(62);
8655 }
8656
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].xofs,f))
8657 {
8658 new_return(63);
8659 }
8660
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].yofs,f))
8661 {
8662 new_return(64);
8663 }
8664
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
8665 {
8666 new_return(65);
8667 }
8668
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
8669 {
8670 new_return(66);
8671 }
8672
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
8673 {
8674 new_return(67);
8675 }
8676
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hysz,f))
8677 {
8678 new_return(68);
8679 }
8680
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
8681 {
8682 new_return(69);
8683 }
8684
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_xofs,f))
8685 {
8686 new_return(70);
8687 }
8688
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_yofs,f))
8689 {
8690 new_return(71);
8691 }
8692
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].weaponscript,f))
8693 {
8694 new_return(72);
8695 }
8696
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8697 {
8698 new_return(73);
8699 }
8700
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8701 {
8702
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8703 {
8704 new_return(74);
8705 }
8706 6144 }
8707
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8708 {
8709 new_return(75);
8710 }
8711
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tilew,f))
8712 {
8713 new_return(76);
8714 }
8715
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tileh,f))
8716 {
8717 new_return(77);
8718 }
8719
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
8720 {
8721 new_return(78);
8722 }
8723
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tilew,f))
8724 {
8725 new_return(79);
8726 }
8727
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tileh,f))
8728 {
8729 new_return(80);
8730 }
8731
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].pickup,f))
8732 {
8733 new_return(81);
8734 }
8735
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pstring,f))
8736 {
8737 new_return(82);
8738 }
8739
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8740 {
8741 new_return(83);
8742 }
8743
8744
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8745 {
8746
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8747 {
8748 new_return(84);
8749 }
8750 6144 }
8751
8752 //InitD[] labels
8753
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < 8; q++ )
8754 {
8755
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8756 {
8757
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8758 {
8759 new_return(85);
8760 }
8761 1597440 }
8762
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8763 {
8764
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
8765 {
8766 new_return(86);
8767 }
8768 1597440 }
8769
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8770 {
8771
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8772 {
8773 new_return(87);
8774 }
8775 1597440 }
8776
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8777 {
8778 new_return(88);
8779 }
8780 24576 }
8781
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < 2; q++ )
8782 {
8783
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].sprite_initiala[q],f))
8784 {
8785 new_return(89);
8786 }
8787
8788 6144 }
8789
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].sprite_script,f))
8790 {
8791 new_return(90);
8792 }
8793
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickupflag,f))
8794 {
8795 new_return(91);
8796 }
8797
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 std::string dispname(itemsbuf[i].display_name);
8798
2/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3072 times.
✗ Branch 3 not taken.
3072 if(!p_putcstr(dispname,f))
8799 new_return(92);
8800
2/2
✓ Branch 0 taken 15360 times.
✓ Branch 1 taken 3072 times.
18432 for(int q = 0; q < WPNSPR_MAX; ++q)
8801 {
8802
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].burnsprs[q], f))
8803 new_return(93);
8804
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].light_rads[q], f))
8805 new_return(94);
8806 15360 }
8807 3072 }
8808
8809
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8810 {
8811 6 section_size=writesize;
8812 6 }
8813 12 }
8814
8815
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8816 {
8817 char ebuf[80];
8818 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8819 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8820 }
8821
8822 6 new_return(0);
8823 }
8824
8825 6 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8826 {
8827 //these are here to bypass compiler warnings about unused arguments
8828 6 Header=Header;
8829
8830 6 dword section_id=ID_WEAPONS;
8831 6 dword section_version=V_WEAPONS;
8832 6 dword section_cversion=CV_WEAPONS;
8833 6 dword section_size = 0;
8834
8835 //section id
8836
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8837 {
8838 new_return(1);
8839 }
8840
8841 //section version info
8842
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8843 {
8844 new_return(2);
8845 }
8846
8847
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8848 {
8849 new_return(3);
8850 }
8851
8852
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8853 {
8854 12 fake_pack_writing=(writecycle==0);
8855
8856 //section size
8857
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8858 {
8859 new_return(4);
8860 }
8861
8862 12 writesize=0;
8863
8864 //finally... section data
8865
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXWPNS,f))
8866 {
8867 new_return(5);
8868 }
8869
8870
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8871 {
8872
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite((char *)weapon_string[i], 64, f))
8873 {
8874 new_return(5);
8875 }
8876 3072 }
8877
8878
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8879 {
8880
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].misc,f))
8881 {
8882 new_return(7);
8883 }
8884
8885
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].csets,f))
8886 {
8887 new_return(8);
8888 }
8889
8890
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].frames,f))
8891 {
8892 new_return(9);
8893 }
8894
8895
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].speed,f))
8896 {
8897 new_return(10);
8898 }
8899
8900
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].type,f))
8901 {
8902 new_return(11);
8903 }
8904
8905
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(wpnsbuf[i].script,f))
8906 {
8907 new_return(12);
8908 }
8909
8910
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(wpnsbuf[i].tile,f))
8911 {
8912 new_return(12);
8913 }
8914 3072 }
8915
8916
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8917 {
8918 6 section_size=writesize;
8919 6 }
8920 12 }
8921
8922
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8923 {
8924 char ebuf[80];
8925 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8926 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8927 }
8928
8929 6 new_return(0);
8930 }
8931
8932 4080 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8933 {
8934
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4080 times.
4080 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8935 return qe_invalid;
8936
8937 4080 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8938 4080 bool is_0x80_screen = j >= 0x80;
8939
8940
1/2
✓ Branch 0 taken 4080 times.
✗ Branch 1 not taken.
4080 if(!p_putc(screen.valid,f))
8941 return qe_invalid;
8942
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 1998 times.
4080 if(!(screen.valid & mVALID))
8943 1998 return qe_OK;
8944 //Calculate what needs writing
8945 2082 uint32_t scr_has_flags = 0;
8946
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2080 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2082 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8947
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8948 2082 scr_has_flags |= SCRHAS_ROOMDATA;
8949
7/8
✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 282 times.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 1680 times.
✓ Branch 4 taken 112 times.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 112 times.
2082 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8950 290 scr_has_flags |= SCRHAS_ITEM;
8951
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8952 18 scr_has_flags |= SCRHAS_TWARP;
8953
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 7754 times.
9650 else for(auto q = 0; q < 4; ++q)
8954 {
8955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7586 times.
15340 if(screen.tilewarptype[q]
8956
2/2
✓ Branch 0 taken 7588 times.
✓ Branch 1 taken 166 times.
7754 || screen.tilewarpdmap[q]
8957
2/2
✓ Branch 0 taken 7586 times.
✓ Branch 1 taken 2 times.
7588 || screen.tilewarpscr[q])
8958 {
8959 168 scr_has_flags |= SCRHAS_TWARP;
8960 168 break;
8961 }
8962 7586 }
8963
3/4
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
2082 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8964
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 2 times.
2078 || screen.sidewarpoverlayflags)
8965 6 scr_has_flags |= SCRHAS_SWARP;
8966
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 3984 times.
4620 else for(auto q = 0; q < 4; ++q)
8967 {
8968
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2544 times.
6536 if(screen.sidewarptype[q] != wtSCROLL
8969
2/2
✓ Branch 0 taken 2560 times.
✓ Branch 1 taken 1424 times.
3984 || screen.sidewarpdmap[q]
8970
2/2
✓ Branch 0 taken 2552 times.
✓ Branch 1 taken 8 times.
2560 || screen.sidewarpscr[q])
8971 {
8972 1440 scr_has_flags |= SCRHAS_SWARP;
8973 1440 break;
8974 }
8975 2544 }
8976
3/4
✓ Branch 0 taken 2038 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2038 times.
2082 if(screen.warparrivalx || screen.warparrivaly)
8977 44 scr_has_flags |= SCRHAS_WARPRET;
8978
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 6388 times.
7838 else for(auto q = 0; q < 4; ++q)
8979 {
8980
3/4
✓ Branch 0 taken 5800 times.
✓ Branch 1 taken 588 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5800 times.
6388 if(screen.warpreturnx[q] || screen.warpreturny[q])
8981 {
8982 588 scr_has_flags |= SCRHAS_WARPRET;
8983 588 break;
8984 }
8985 5800 }
8986
8987
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2082 times.
2082 if(screen.hidelayers || screen.hidescriptlayers)
8988 scr_has_flags |= SCRHAS_LAYERS;
8989
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 11548 times.
13438 else for(auto q = 0; q < 6; ++q)
8990 {
8991
4/4
✓ Branch 0 taken 11366 times.
✓ Branch 1 taken 182 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 11356 times.
11548 if(screen.layermap[q] || screen.layerscreen[q]
8992
1/2
✓ Branch 0 taken 11366 times.
✗ Branch 1 not taken.
11366 || screen.layeropacity[q]!=255)
8993 {
8994 192 scr_has_flags |= SCRHAS_LAYERS;
8995 192 break;
8996 }
8997 11356 }
8998
8999
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2078 times.
2082 if(screen.exitdir)
9000 4 scr_has_flags |= SCRHAS_MAZE;
9001
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 8312 times.
10390 else for(auto q = 0; q < 4; ++q)
9002 {
9003
1/2
✓ Branch 0 taken 8312 times.
✗ Branch 1 not taken.
8312 if(screen.path[q])
9004 {
9005 scr_has_flags |= SCRHAS_MAZE;
9006 break;
9007 }
9008 8312 }
9009
9010
4/4
✓ Branch 0 taken 1848 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 238 times.
✓ Branch 3 taken 752 times.
3072 if(screen.door_combo_set || screen.stairx
9011
3/4
✓ Branch 0 taken 1820 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 1820 times.
✗ Branch 3 not taken.
1848 || screen.stairy || screen.undercombo
9012
2/2
✓ Branch 0 taken 990 times.
✓ Branch 1 taken 830 times.
1820 || screen.undercset)
9013 1330 scr_has_flags |= SCRHAS_D_S_U;
9014
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 812 times.
832 else for(auto q = 0; q < 4; ++q)
9015 {
9016
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 732 times.
812 if(screen.door[q] != dNONE)
9017 {
9018 732 scr_has_flags |= SCRHAS_D_S_U;
9019 732 break;
9020 }
9021 80 }
9022
9023
2/2
✓ Branch 0 taken 1822 times.
✓ Branch 1 taken 260 times.
3540 if(screen.flags || screen.flags2
9024
4/4
✓ Branch 0 taken 1736 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 1702 times.
✓ Branch 3 taken 34 times.
1822 || screen.flags3 || screen.flags4
9025
4/4
✓ Branch 0 taken 1688 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 1674 times.
✓ Branch 3 taken 14 times.
1702 || screen.flags5 || screen.flags6
9026
4/4
✓ Branch 0 taken 1466 times.
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 1458 times.
✓ Branch 3 taken 8 times.
1674 || screen.flags7 || screen.flags8
9027
2/4
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1458 times.
✗ Branch 3 not taken.
1458 || screen.flags9 || screen.flags10
9028
1/2
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
1458 || screen.enemyflags)
9029 2082 scr_has_flags |= SCRHAS_FLAGS;
9030
9031
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 2032 times.
2082 if(screen.pattern)
9032 50 scr_has_flags |= SCRHAS_ENEMY;
9033
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 14560 times.
15952 else for(auto q = 0; q < 10; ++q)
9034 {
9035
2/2
✓ Branch 0 taken 13920 times.
✓ Branch 1 taken 640 times.
14560 if(screen.enemy[q])
9036 {
9037 640 scr_has_flags |= SCRHAS_ENEMY;
9038 640 break;
9039 }
9040 13920 }
9041
9042
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
4158 if(screen.noreset || screen.nocarry
9043
3/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2076 times.
✓ Branch 3 taken 6 times.
2082 || screen.nextmap || screen.nextscr)
9044 6 scr_has_flags |= SCRHAS_CARRY;
9045
9046
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if(screen.script || screen.preloadscript)
9047 18 scr_has_flags |= SCRHAS_SCRIPT;
9048
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 16512 times.
18576 else for(auto q = 0; q < 8; ++q)
9049 {
9050
1/2
✓ Branch 0 taken 16512 times.
✗ Branch 1 not taken.
16512 if(screen.screeninitd[q])
9051 {
9052 scr_has_flags |= SCRHAS_SCRIPT;
9053 break;
9054 }
9055 16512 }
9056
9057
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 99352 times.
100110 for(auto q = 0; q < 128; ++q)
9058 {
9059
1/2
✓ Branch 0 taken 98028 times.
✗ Branch 1 not taken.
197380 if(screen.secretcombo[q]
9060
2/2
✓ Branch 0 taken 98030 times.
✓ Branch 1 taken 1322 times.
99352 || screen.secretcset[q]
9061
2/2
✓ Branch 0 taken 98028 times.
✓ Branch 1 taken 2 times.
98030 || screen.secretflag[q])
9062 {
9063 1324 scr_has_flags |= SCRHAS_SECRETS;
9064 1324 break;
9065 }
9066 98028 }
9067
9068
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 40228 times.
40400 for(auto q = 0; q < 176; ++q)
9069 {
9070
4/4
✓ Branch 0 taken 38408 times.
✓ Branch 1 taken 1820 times.
✓ Branch 2 taken 38318 times.
✓ Branch 3 taken 2 times.
40228 if(screen.data[q] || screen.cset[q]
9071
2/2
✓ Branch 0 taken 38320 times.
✓ Branch 1 taken 88 times.
38408 || screen.sflag[q])
9072 {
9073 1910 scr_has_flags |= SCRHAS_COMBOFLAG;
9074 1910 break;
9075 }
9076 38318 }
9077
9078
2/2
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 1296 times.
2082 if(screen.color || screen.csensitive != 1
9079
3/4
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 752 times.
✓ Branch 3 taken 34 times.
786 || screen.oceansfx || screen.bosssfx
9080
2/4
✓ Branch 0 taken 752 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 752 times.
752 || screen.secretsfx || screen.holdupsfx
9081 || screen.timedwarptics || screen.screen_midi != -1
9082 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9083 2082 scr_has_flags |= SCRHAS_MISC;
9084
9085
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(scr_has_flags,f))
9086 return qe_invalid;
9087
9088 //Write stuff
9089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_ROOMDATA)
9090 {
9091
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guy,f))
9092 return qe_invalid;
9093
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(screen.guytile,f))
9094 return qe_invalid;
9095
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guycs,f))
9096 return qe_invalid;
9097
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.roomflags,f))
9098 return qe_invalid;
9099
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.str,f))
9100 return qe_invalid;
9101
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.room,f))
9102 return qe_invalid;
9103
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.catchall,f))
9104 return qe_invalid;
9105 2082 }
9106
2/2
✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 290 times.
2082 if(scr_has_flags & SCRHAS_ITEM)
9107 {
9108
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.item,f))
9109 return qe_invalid;
9110
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.hasitem,f))
9111 return qe_invalid;
9112
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemx,f))
9113 return qe_invalid;
9114
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemy,f))
9115 return qe_invalid;
9116 290 }
9117
2/2
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 1500 times.
2082 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9118 {
9119
1/2
✓ Branch 0 taken 1500 times.
✗ Branch 1 not taken.
1500 if(!p_iputw(screen.warpreturnc,f))
9120 return qe_invalid;
9121 1500 }
9122
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 186 times.
2082 if(scr_has_flags & SCRHAS_TWARP)
9123 {
9124
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9125 {
9126
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarptype[k],f))
9127 return qe_invalid;
9128 744 }
9129
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9130 {
9131
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_iputw(screen.tilewarpdmap[k],f))
9132 return qe_invalid;
9133 744 }
9134
9135
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9136 {
9137
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarpscr[k],f))
9138 return qe_invalid;
9139 744 }
9140
9141
1/2
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
186 if(!p_putc(screen.tilewarpoverlayflags,f))
9142 return qe_invalid;
9143 186 }
9144
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 1446 times.
2082 if(scr_has_flags & SCRHAS_SWARP)
9145 {
9146
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9147 {
9148
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarptype[k],f))
9149 return qe_invalid;
9150 5784 }
9151
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9152 {
9153
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_iputw(screen.sidewarpdmap[k],f))
9154 return qe_invalid;
9155 5784 }
9156
9157
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9158 {
9159
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarpscr[k],f))
9160 return qe_invalid;
9161 5784 }
9162
9163
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpoverlayflags,f))
9164 return qe_invalid;
9165
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpindex,f))
9166 return qe_invalid;
9167 1446 }
9168
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 632 times.
2082 if(scr_has_flags & SCRHAS_WARPRET)
9169 {
9170
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9171 {
9172
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturnx[k],f))
9173 return qe_invalid;
9174 2528 }
9175
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9176 {
9177
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturny[k],f))
9178 return qe_invalid;
9179 2528 }
9180
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivalx,f))
9181 return qe_invalid;
9182
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivaly,f))
9183 return qe_invalid;
9184 632 }
9185
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 192 times.
2082 if(scr_has_flags & SCRHAS_LAYERS)
9186 {
9187
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9188 {
9189
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layermap[k],f))
9190 return qe_invalid;
9191 1152 }
9192
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9193 {
9194
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layerscreen[k],f))
9195 return qe_invalid;
9196 1152 }
9197
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9198 {
9199
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layeropacity[k],f))
9200 return qe_invalid;
9201 1152 }
9202
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidelayers,f))
9203 return qe_invalid;
9204
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidescriptlayers,f))
9205 return qe_invalid;
9206 192 }
9207
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(scr_has_flags & SCRHAS_MAZE)
9208 {
9209
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for(int32_t k=0; k<4; k++)
9210 {
9211
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_putc(screen.path[k],f))
9212 return qe_invalid;
9213 16 }
9214
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_putc(screen.exitdir,f))
9215 return qe_invalid;
9216 4 }
9217
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2062 times.
2082 if(scr_has_flags & SCRHAS_D_S_U)
9218 {
9219
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.door_combo_set,f))
9220 return qe_invalid;
9221
2/2
✓ Branch 0 taken 8248 times.
✓ Branch 1 taken 2062 times.
10310 for(int32_t k=0; k<4; k++)
9222 {
9223
1/2
✓ Branch 0 taken 8248 times.
✗ Branch 1 not taken.
8248 if(!p_putc(screen.door[k],f))
9224 return qe_invalid;
9225 8248 }
9226
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairx,f))
9227 return qe_invalid;
9228
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairy,f))
9229 return qe_invalid;
9230
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.undercombo,f))
9231 return qe_invalid;
9232
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.undercset,f))
9233 return qe_invalid;
9234 2062 }
9235
2/2
✓ Branch 0 taken 1336 times.
✓ Branch 1 taken 746 times.
2082 if(scr_has_flags & SCRHAS_FLAGS)
9236 {
9237
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags,f))
9238 return qe_invalid;
9239
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags2,f))
9240 return qe_invalid;
9241
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags3,f))
9242 return qe_invalid;
9243
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags4,f))
9244 return qe_invalid;
9245
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags5,f))
9246 return qe_invalid;
9247
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags6,f))
9248 return qe_invalid;
9249
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags7,f))
9250 return qe_invalid;
9251
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags8,f))
9252 return qe_invalid;
9253
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags9,f))
9254 return qe_invalid;
9255
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags10,f))
9256 return qe_invalid;
9257
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.enemyflags,f))
9258 return qe_invalid;
9259 746 }
9260
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 690 times.
2082 if(scr_has_flags & SCRHAS_ENEMY)
9261 {
9262
2/2
✓ Branch 0 taken 6900 times.
✓ Branch 1 taken 690 times.
7590 for(int32_t k=0; k<10; k++)
9263 {
9264
1/2
✓ Branch 0 taken 6900 times.
✗ Branch 1 not taken.
6900 if(!p_iputw(screen.enemy[k],f))
9265 return qe_invalid;
9266 6900 }
9267
1/2
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
690 if(!p_putc(screen.pattern,f))
9268 return qe_invalid;
9269 690 }
9270
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 6 times.
2082 if(scr_has_flags & SCRHAS_CARRY)
9271 {
9272
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.noreset,f))
9273 return qe_invalid;
9274
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.nocarry,f))
9275 return qe_invalid;
9276
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextmap,f))
9277 return qe_invalid;
9278
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextscr,f))
9279 return qe_invalid;
9280 6 }
9281
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
2082 if(scr_has_flags & SCRHAS_SCRIPT)
9282 {
9283
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(screen.script,f))
9284 return qe_invalid;
9285
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(screen.preloadscript,f))
9286 return qe_invalid;
9287
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for ( int32_t q = 0; q < 8; q++ )
9288 {
9289
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_iputl(screen.screeninitd[q],f))
9290 return qe_invalid;
9291 144 }
9292 18 }
9293
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 1324 times.
2082 if(scr_has_flags & SCRHAS_SECRETS)
9294 {
9295
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9296 {
9297
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_iputw(screen.secretcombo[k],f))
9298 return qe_invalid;
9299 169472 }
9300
9301
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9302 {
9303
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretcset[k],f))
9304 return qe_invalid;
9305 169472 }
9306
9307
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9308 {
9309
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretflag[k],f))
9310 return qe_invalid;
9311 169472 }
9312 1324 }
9313
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 1910 times.
2082 if(scr_has_flags & SCRHAS_COMBOFLAG)
9314 {
9315
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9316 {
9317
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_iputw(screen.data[k],f))
9318 return qe_invalid;
9319 336160 }
9320
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9321 {
9322
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.sflag[k],f))
9323 return qe_invalid;
9324 336160 }
9325
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9326 {
9327
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.cset[k],f))
9328 return qe_invalid;
9329 336160 }
9330 1910 }
9331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_MISC)
9332 {
9333
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.color,f))
9334 return qe_invalid;
9335
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.csensitive,f))
9336 return qe_invalid;
9337
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.oceansfx,f))
9338 return qe_invalid;
9339
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.bosssfx,f))
9340 return qe_invalid;
9341
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.secretsfx,f))
9342 return qe_invalid;
9343
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.holdupsfx,f))
9344 return qe_invalid;
9345
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.timedwarptics,f))
9346 return qe_invalid;
9347
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.screen_midi,f))
9348 return qe_invalid;
9349
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_layer,f))
9350 return qe_invalid;
9351
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_show,f))
9352 return qe_invalid;
9353
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_hide,f))
9354 return qe_invalid;
9355 2082 }
9356
9357 2082 dword numffc = screen.numFFC();
9358
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(numffc,f))
9359 return qe_invalid;
9360
2/2
✓ Branch 0 taken 45298 times.
✓ Branch 1 taken 2082 times.
47380 for(int32_t k=0; k<numffc; ++k)
9361 {
9362 45298 ffcdata const& tempffc = screen.ffcs[k];
9363
9364
1/2
✓ Branch 0 taken 45298 times.
✗ Branch 1 not taken.
45298 if(!p_iputw(tempffc.data,f))
9365 return qe_invalid;
9366
9367
2/2
✓ Branch 0 taken 44208 times.
✓ Branch 1 taken 1090 times.
45298 if(!tempffc.data) //don't save the rest of the ffc
9368 44208 continue;
9369
9370
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.cset,f))
9371 return qe_invalid;
9372
9373
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.delay,f))
9374 return qe_invalid;
9375
9376
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.x,f))
9377 return qe_invalid;
9378
9379
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.y,f))
9380 return qe_invalid;
9381
9382
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vx,f))
9383 return qe_invalid;
9384
9385
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vy,f))
9386 return qe_invalid;
9387
9388
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ax,f))
9389 return qe_invalid;
9390
9391
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ay,f))
9392 return qe_invalid;
9393
9394
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.link,f))
9395 return qe_invalid;
9396
9397
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_width,f))
9398 return qe_invalid;
9399
9400
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_height,f))
9401 return qe_invalid;
9402
9403
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.txsz,f))
9404 return qe_invalid;
9405
9406
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.tysz,f))
9407 return qe_invalid;
9408
9409
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.flags,f))
9410 return qe_invalid;
9411
9412
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.script,f))
9413 return qe_invalid;
9414
9415
2/2
✓ Branch 0 taken 8720 times.
✓ Branch 1 taken 1090 times.
9810 for(auto q = 0; q < 8; ++q)
9416 {
9417
1/2
✓ Branch 0 taken 8720 times.
✗ Branch 1 not taken.
8720 if(!p_iputl(tempffc.initd[q],f))
9418 return qe_invalid;
9419 8720 }
9420
9421
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[0]/10000,f))
9422 return qe_invalid;
9423
9424
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[1]/10000,f))
9425 return qe_invalid;
9426 1090 }
9427
9428
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putlstr(screen.usr_notes, f))
9429 return qe_invalid;
9430
9431 2082 return qe_OK;
9432 4080 }
9433
9434 6 int32_t writemaps(PACKFILE *f, zquestheader *)
9435 {
9436 6 dword section_id=ID_MAPS;
9437 6 dword section_version=V_MAPS;
9438 6 dword section_cversion=CV_MAPS;
9439 6 dword section_size = 0;
9440
9441 //section id
9442
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9443 {
9444 new_return(1);
9445 }
9446
9447 //section version info
9448
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9449 {
9450 new_return(2);
9451 }
9452
9453
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
9454 {
9455 new_return(3);
9456 }
9457
9458
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9459 {
9460 12 fake_pack_writing=(writecycle==0);
9461
9462 //section size
9463
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9464 {
9465 new_return(4);
9466 }
9467
9468 12 writesize=0;
9469
9470
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(map_count,f))
9471 {
9472 new_return(5);
9473 }
9474 12 map_autolayers.resize(map_count*6);
9475
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 12 times.
42 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9476 {
9477 30 byte valid = 0;
9478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 for(int32_t j=0; j<MAPSCRS; j++)
9479 {
9480
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9481 break;
9482 240 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9483
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 210 times.
240 if(screen.valid & mVALID)
9484 {
9485 30 valid = 1;
9486 30 break;
9487 }
9488 210 }
9489
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_putc(valid,f))
9490 {
9491 new_return(6);
9492 }
9493
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!valid) continue;
9494
9495 { //per-map info
9496
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 30 times.
210 for(int q = 0; q < 6; ++q)
9497 {
9498 180 size_t ind = i*6+q;
9499
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 if(!p_iputw(map_autolayers[ind],f))
9500 new_return(7);
9501 180 }
9502 }
9503
9504
2/2
✓ Branch 0 taken 4080 times.
✓ Branch 1 taken 30 times.
4110 for(int32_t j=0; j<MAPSCRS; j++)
9505 4080 writemapscreen(f,i,j);
9506 30 }
9507
9508
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9509 {
9510 6 section_size=writesize;
9511 6 }
9512 12 }
9513
9514
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9515 {
9516 char ebuf[80];
9517 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9518 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9519 }
9520
9521 6 new_return(0);
9522 }
9523
9524 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9525 {
9526 //Check what needs writing
9527 byte combo_has_flags = 0;
9528 383638 for(auto q = 0; q < 8; ++q)
9529 {
9530 767276 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9531 383638 || (q < 4 && tmp_cmb.attributes[q]))
9532 {
9533 combo_has_flags |= CHAS_ATTRIB;
9534 break;
9535 }
9536 383638 }
9537
3/4
✓ Branch 0 taken 96864 times.
✓ Branch 1 taken 96864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96836 times.
96836 if (tmp_cmb.triggerflags[0] || tmp_cmb.triggerflags[1]
9538
3/4
✓ Branch 0 taken 96862 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96862 times.
✗ Branch 3 not taken.
96864 || tmp_cmb.triggerflags[2] || tmp_cmb.triggerflags[3]
9539
3/4
✓ Branch 0 taken 96860 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96862 || tmp_cmb.triggerflags[4] || tmp_cmb.triggerflags[5]
9540
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerlevel || tmp_cmb.trig_lstate
9541
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trig_gstate || tmp_cmb.trig_statetime
9542
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerbtn || tmp_cmb.triggeritem
9543
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigtimer || tmp_cmb.trigsfx
9544
3/4
✓ Branch 0 taken 96836 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigchange || tmp_cmb.trigprox
9545
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigctr || tmp_cmb.trigctramnt
9546
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglbeam || tmp_cmb.trigcschange
9547
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.spawnitem || tmp_cmb.spawnenemy
9548
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.exstate > -1 || tmp_cmb.spawnip
9549
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.exdoor_dir > -1
9550
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigcopycat || tmp_cmb.trigcooldown
9551
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_genscr || tmp_cmb.trig_group
9552
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_group_val || tmp_cmb.trig_levelitems
9553
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.trigdmlevel > -1
9554
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglvlpalette > -1 || tmp_cmb.trigbosspalette > -1
9555
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigquaketime > -1 || tmp_cmb.trigwavytime > -1
9556
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_swjinxtime > -2 || tmp_cmb.trig_itmjinxtime > -2
9557
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_stuntime > -2 || tmp_cmb.trig_bunnytime > -2
9558
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_pushtime != 8 || tmp_cmb.trig_shieldjinxtime > -2
9559
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_cid || tmp_cmb.prompt_cs
9560
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_x != 12 || tmp_cmb.prompt_y != -8)
9561 96892 combo_has_flags |= CHAS_TRIG;
9562
2/2
✓ Branch 0 taken 290508 times.
✓ Branch 1 taken 96836 times.
387344 else for(int q = 0; q < 3; ++q)
9563
1/2
✓ Branch 0 taken 290508 times.
✗ Branch 1 not taken.
290508 if(tmp_cmb.trigtint[q])
9564 combo_has_flags |= CHAS_TRIG;
9565
4/4
✓ Branch 0 taken 96840 times.
✓ Branch 1 taken 96888 times.
✓ Branch 2 taken 96704 times.
✓ Branch 3 taken 136 times.
193728 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9566 193592 combo_has_flags |= CHAS_FLAG;
9567
6/6
✓ Branch 0 taken 93610 times.
✓ Branch 1 taken 93290 times.
✓ Branch 2 taken 80124 times.
✓ Branch 3 taken 13486 times.
✓ Branch 4 taken 89494 times.
✓ Branch 5 taken 9434 times.
80380 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9568
6/6
✓ Branch 0 taken 80100 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 80070 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 80060 times.
✓ Branch 5 taken 10 times.
80124 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9569
1/2
✓ Branch 0 taken 80060 times.
✗ Branch 1 not taken.
80060 || tmp_cmb.animflags)
9570 196334 combo_has_flags |= CHAS_ANIM;
9571
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 70224 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 97004 times.
26780 if(tmp_cmb.script || tmp_cmb.label.size())
9572 70224 combo_has_flags |= CHAS_SCRIPT;
9573
2/2
✓ Branch 0 taken 776032 times.
✓ Branch 1 taken 97004 times.
873036 else for(auto q = 0; q < 8; ++q)
9574 {
9575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 776032 times.
776032 if(tmp_cmb.initd[q])
9576 {
9577 combo_has_flags |= CHAS_SCRIPT;
9578 break;
9579 }
9580 776032 }
9581
6/6
✓ Branch 0 taken 52696 times.
✓ Branch 1 taken 114532 times.
✓ Branch 2 taken 52184 times.
✓ Branch 3 taken 512 times.
✓ Branch 4 taken 70224 times.
✓ Branch 5 taken 18040 times.
219412 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9582
2/4
✓ Branch 0 taken 52184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52184 times.
✗ Branch 3 not taken.
52184 || tmp_cmb.type || tmp_cmb.csets)
9583 185268 combo_has_flags |= CHAS_BASIC;
9584
3/4
✓ Branch 0 taken 96996 times.
✓ Branch 1 taken 34136 times.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
159856 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9585
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9586
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9587
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9588
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9589
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9590
1/2
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
96996 || tmp_cmb.lift_parent_item)
9591 131132 combo_has_flags |= CHAS_LIFT;
9592
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
✓ Branch 2 taken 97004 times.
✗ Branch 3 not taken.
228128 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9593
7/10
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 97000 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 96996 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
97004 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9594
5/10
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
96996 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap)
9595 131132 combo_has_flags |= CHAS_GENERAL;
9596
9597
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
131132 if(!p_putc(combo_has_flags,f))
9598 {
9599 34128 return 50;
9600 }
9601
2/2
✓ Branch 0 taken 44820 times.
✓ Branch 1 taken 52184 times.
97004 if(!combo_has_flags) return 0; //Valid, done reading
9602 //Write the combo
9603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44820 times.
44820 if(combo_has_flags&CHAS_BASIC)
9604 {
9605
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_iputl(tmp_cmb.o_tile,f))
9606 return 6;
9607
9608
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flip,f))
9609 return 7;
9610
9611
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.walk,f))
9612 return 8;
9613
9614
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.type,f))
9615 return 9;
9616
9617
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flag,f))
9618 return 15;
9619
9620
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.csets,f))
9621 return 10;
9622 44820 }
9623
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(combo_has_flags&CHAS_SCRIPT)
9624 {
9625 p_putcstr(tmp_cmb.label, f);
9626
9627 if(!p_iputw(tmp_cmb.script,f))
9628 return 26;
9629 for ( int32_t q = 0; q < 8; q++ )
9630 if(!p_iputl(tmp_cmb.initd[q],f))
9631 return 27;
9632 }
9633
2/2
✓ Branch 0 taken 27474 times.
✓ Branch 1 taken 17346 times.
44820 if(combo_has_flags&CHAS_ANIM)
9634 {
9635
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.frames,f))
9636 return 11;
9637
9638
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.speed,f))
9639 return 12;
9640
9641
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_iputw(tmp_cmb.nextcombo,f))
9642 return 13;
9643
9644
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.nextcset,f))
9645 return 14;
9646
9647
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanim,f))
9648 return 16;
9649
9650
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanimy,f))
9651 return 18;
9652
9653
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.animflags,f))
9654 return 19;
9655 17346 }
9656
2/2
✓ Branch 0 taken 42552 times.
✓ Branch 1 taken 2268 times.
44820 if(combo_has_flags&CHAS_ATTRIB)
9657 {
9658
2/2
✓ Branch 0 taken 9072 times.
✓ Branch 1 taken 2268 times.
11340 for ( int32_t q = 0; q < 4; q++ )
9659
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9072 times.
9072 if(!p_iputl(tmp_cmb.attributes[q],f))
9660 return 20;
9661
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ )
9662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_putc(tmp_cmb.attribytes[q],f))
9663 return 25;
9664
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9666 return 32;
9667 2268 }
9668
2/2
✓ Branch 0 taken 44636 times.
✓ Branch 1 taken 184 times.
44820 if(combo_has_flags&CHAS_FLAG)
9669 {
9670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
184 if(!p_iputl(tmp_cmb.usrflags,f))
9671 return 21;
9672
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if(!p_iputw(tmp_cmb.genflags,f))
9673 return 33;
9674 184 }
9675
2/2
✓ Branch 0 taken 44652 times.
✓ Branch 1 taken 168 times.
44820 if(combo_has_flags&CHAS_TRIG)
9676 {
9677
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 168 times.
1176 for ( int32_t q = 0; q < 6; q++ )
9678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1008 times.
1008 if(!p_iputl(tmp_cmb.triggerflags[q],f))
9679 return 22;
9680
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.triggerlevel,f))
9681 return 23;
9682
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggerbtn,f))
9683 return 34;
9684
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggeritem,f))
9685 return 35;
9686
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigtimer,f))
9687 return 36;
9688
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigsfx,f))
9689 return 37;
9690
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigchange,f))
9691 return 38;
9692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if(!p_iputw(tmp_cmb.trigprox,f))
9693 return 39;
9694
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigctr,f))
9695 return 40;
9696
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigctramnt,f))
9697 return 41;
9698
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triglbeam,f))
9699 return 42;
9700
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcschange,f))
9701 return 43;
9702
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnitem,f))
9703 return 44;
9704
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnenemy,f))
9705 return 45;
9706
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exstate,f))
9707 return 46;
9708
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.spawnip,f))
9709 return 47;
9710
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcopycat,f))
9711 return 48;
9712
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcooldown,f))
9713 return 49;
9714
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_cid,f))
9715 return 50;
9716
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.prompt_cs,f))
9717 return 51;
9718
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_x,f))
9719 return 52;
9720
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_y,f))
9721 return 53;
9722
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_lstate,f))
9723 return 69;
9724
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_gstate,f))
9725 return 70;
9726
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trig_statetime,f))
9727 return 71;
9728
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_genscr,f))
9729 return 72;
9730
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_group,f))
9731 return 76;
9732
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_group_val,f))
9733 return 77;
9734
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_dir,f))
9735 return 89;
9736
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_ind,f))
9737 return 90;
9738
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_levelitems,f))
9739 return 91;
9740
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigdmlevel,f))
9741 return 92;
9742
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 168 times.
672 for(int q = 0; q < 3; ++q)
9743
1/2
✓ Branch 0 taken 504 times.
✗ Branch 1 not taken.
504 if(!p_iputw(tmp_cmb.trigtint[q],f))
9744 return 93;
9745
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.triglvlpalette,f))
9746 return 94;
9747
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigbosspalette,f))
9748 return 95;
9749
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigquaketime,f))
9750 return 96;
9751
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigwavytime,f))
9752 return 97;
9753
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_swjinxtime,f))
9754 return 98;
9755
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_itmjinxtime,f))
9756 return 99;
9757
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_stuntime,f))
9758 return 100;
9759
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_bunnytime,f))
9760 return 101;
9761
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_pushtime,f))
9762 return 102;
9763
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if (!p_iputw(tmp_cmb.trig_shieldjinxtime, f))
9764 return 103;
9765 168 }
9766
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_LIFT)
9767 {
9768
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftcmb,f))
9769 return 54;
9770
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftcs,f))
9771 return 55;
9772
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftundercmb,f))
9773 return 56;
9774
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftundercs,f))
9775 return 57;
9776
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftdmg,f))
9777 return 58;
9778
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftlvl,f))
9779 return 59;
9780
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftitm,f))
9781 return 60;
9782
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftflags,f))
9783 return 61;
9784
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftgfx,f))
9785 return 62;
9786
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsprite,f))
9787 return 63;
9788
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsfx,f))
9789 return 64;
9790
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9791 return 65;
9792
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9793 return 66;
9794
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifthei,f))
9795 return 67;
9796
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifttime,f))
9797 return 68;
9798
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lift_parent_item,f))
9799 return 78;
9800 8 }
9801
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_GENERAL)
9802 {
9803
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_mult,f))
9804 return 73;
9805
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_div,f))
9806 return 74;
9807
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputzf(tmp_cmb.speed_add,f))
9808 return 75;
9809
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_appear,f))
9810 return 79;
9811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(!p_putc(tmp_cmb.sfx_disappear,f))
9812 return 80;
9813
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_loop,f))
9814 return 81;
9815
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_walking,f))
9816 return 82;
9817
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_standing,f))
9818 return 83;
9819
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_appear,f))
9820 return 84;
9821
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_disappear,f))
9822 return 85;
9823
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_walking,f))
9824 return 86;
9825
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_standing,f))
9826 return 87;
9827
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_tap,f))
9828 return 88;
9829 8 }
9830 44820 return 0;
9831 131132 }
9832
9833 6 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9834 {
9835 //these are here to bypass compiler warnings about unused arguments
9836 6 version=version;
9837 6 build=build;
9838
9839 word combos_used;
9840 6 dword section_id=ID_COMBOS;
9841 6 dword section_version=V_COMBOS;
9842 6 dword section_cversion=CV_COMBOS;
9843 // dword section_size=0;
9844 6 combos_used = count_combos()-start_combo;
9845
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, max_combos);
9846
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, MAXCOMBOS);
9847 6 dword section_size = 0;
9848
9849 //section id
9850
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9851 {
9852 new_return(1);
9853 }
9854
9855 //section version info
9856
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9857 {
9858 new_return(2);
9859 }
9860
9861
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
9862 {
9863 new_return(3);
9864 }
9865
9866
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9867 {
9868 12 fake_pack_writing=(writecycle==0);
9869
9870 //section size
9871
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9872 {
9873 new_return(4);
9874 }
9875
9876 12 writesize=0;
9877
9878 //finally... section data
9879 12 combos_used=count_combos()-start_combo;
9880
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, max_combos);
9881
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, MAXCOMBOS);
9882
9883
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(combos_used,f))
9884 {
9885 new_return(5);
9886 }
9887
9888 12 size_t end_combo = start_combo+combos_used;
9889
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 12 times.
97016 for(size_t q = start_combo; q < end_combo; ++q)
9890 {
9891 97004 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9892
1/4
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
97004 if(ret) new_return(ret);
9893 97004 }
9894
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9895 {
9896 6 section_size=writesize;
9897 6 }
9898 12 }
9899
9900
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9901 {
9902 char ebuf[80];
9903 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9904 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9905 }
9906
9907 6 new_return(0);
9908 6 }
9909
9910 6 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9911 {
9912 //these are here to bypass compiler warnings about unused arguments
9913 6 version=version;
9914 6 build=build;
9915
9916 6 dword section_id=ID_COMBOALIASES;
9917 6 dword section_version=V_COMBOALIASES;
9918 6 dword section_cversion=CV_COMBOALIASES;
9919 6 dword section_size=0;
9920
9921 //section id
9922
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9923 {
9924 new_return(1);
9925 }
9926
9927 //section version info
9928
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9929 {
9930 new_return(2);
9931 }
9932
9933
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
9934 {
9935 new_return(3);
9936 }
9937
9938
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9939 {
9940 12 fake_pack_writing=(writecycle==0);
9941
9942 //section size
9943
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9944 {
9945 new_return(4);
9946 }
9947
9948 12 writesize=0;
9949
9950 //finally... section data
9951
2/2
✓ Branch 0 taken 98304 times.
✓ Branch 1 taken 12 times.
98316 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
9952 {
9953
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_iputw(combo_aliases[j].combo,f))
9954 {
9955 new_return(5);
9956 }
9957
9958
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].cset,f))
9959 {
9960 new_return(6);
9961 }
9962
9963 98304 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
9964
9965
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].width,f))
9966 {
9967 new_return(7);
9968 }
9969
9970
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].height,f))
9971 {
9972 new_return(8);
9973 }
9974
9975
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].layermask,f))
9976 {
9977 new_return(9);
9978 }
9979
9980
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
9981 {
9982
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_iputw(combo_aliases[j].combos[k],f))
9983 {
9984 new_return(10);
9985 }
9986 99792 }
9987
9988
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
9989 {
9990
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_putc(combo_aliases[j].csets[k],f))
9991 {
9992 new_return(11);
9993 }
9994 99792 }
9995 98304 }
9996
9997 //Combo pools!
9998 int16_t num_cpools;
9999
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 98300 times.
98310 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10000 {
10001
2/2
✓ Branch 0 taken 98298 times.
✓ Branch 1 taken 2 times.
98300 if(combo_pools[num_cpools].valid()) //found a used pool
10002 {
10003 2 ++num_cpools;
10004 2 break;
10005 }
10006 98298 }
10007
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if(num_cpools < 0) num_cpools = 0;
10008
10009
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_cpools,f))
10010 {
10011 new_return(12);
10012 }
10013
10014
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(auto cp = 0; cp < num_cpools; ++cp)
10015 {
10016 6 combo_pool const& pool = combo_pools[cp];
10017 6 int32_t num_combos = pool.combos.size();
10018
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10019 {
10020 new_return(13);
10021 }
10022
10023
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10024 {
10025 26 cpool_entry const& entry = pool.combos.at(q);
10026
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10027 {
10028 new_return(14);
10029 }
10030
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10031 {
10032 new_return(15);
10033 }
10034
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10035 {
10036 new_return(16);
10037 }
10038 26 }
10039 6 }
10040
10041 //Autocombos!
10042 int16_t num_cautos;
10043
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 98304 times.
98316 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10044 {
10045
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if (combo_autos[num_cautos].valid()) //found a used autocombo
10046 {
10047 ++num_cautos;
10048 break;
10049 }
10050 98304 }
10051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (num_cautos < 0) num_cautos = 0;
10052
10053
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputw(num_cautos, f))
10054 {
10055 new_return(17);
10056 }
10057
10058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for (auto ca = 0; ca < num_cautos; ++ca)
10059 {
10060 combo_auto const& cauto = combo_autos[ca];
10061 if (!p_putc(cauto.getType(), f))
10062 {
10063 new_return(18);
10064 }
10065 if (!p_iputl(cauto.getIconDisplay(), f))
10066 {
10067 new_return(19);
10068 }
10069 if (!p_iputl(cauto.getEraseCombo(), f))
10070 {
10071 new_return(20);
10072 }
10073 if (!p_putc(cauto.getFlags(), f))
10074 {
10075 new_return(21);
10076 }
10077 if (!p_putc(cauto.getArg(), f))
10078 {
10079 new_return(22);
10080 }
10081 int32_t num_combos = cauto.combos.size();
10082 if (!p_iputl(num_combos, f))
10083 {
10084 new_return(23);
10085 }
10086
10087 for (auto q = 0; q < num_combos; ++q)
10088 {
10089 autocombo_entry const& entry = cauto.combos.at(q);
10090 if (!p_putc(entry.ctype, f))
10091 {
10092 new_return(24);
10093 }
10094 if (!p_iputl(entry.cid, f))
10095 {
10096 new_return(25);
10097 }
10098 }
10099 }
10100
10101
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10102 {
10103 6 section_size=writesize;
10104 6 }
10105 12 }
10106
10107
10108
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10109 {
10110 char ebuf[80];
10111 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10112 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10113 }
10114
10115 6 new_return(0);
10116 }
10117
10118 6 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10119 {
10120 //these are here to bypass compiler warnings about unused arguments
10121 6 version=version;
10122 6 build=build;
10123 6 start_cset=start_cset;
10124 6 max_csets=max_csets;
10125
10126 6 dword section_id=ID_CSETS;
10127 6 dword section_version=V_CSETS;
10128 6 dword section_cversion=CV_CSETS;
10129 6 int32_t palcycles = count_palcycles(&QMisc);
10130 // int32_t palcyccount = count_palcycles(&QMisc);
10131 6 dword section_size = 0;
10132
10133 //section id
10134
10135
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10136 {
10137 new_return(1);
10138 }
10139
10140 //section version info
10141
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10142 {
10143 new_return(2);
10144 }
10145
10146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10147 {
10148 new_return(3);
10149 }
10150
10151
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10152 {
10153 12 fake_pack_writing=(writecycle==0);
10154
10155 //section size
10156
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10157 {
10158 new_return(4);
10159 }
10160
10161 12 writesize=0;
10162
10163 //finally... section data
10164
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(colordata,psTOTAL255,f))
10165 {
10166 new_return(5);
10167 }
10168
10169
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10170 {
10171 new_return(6);
10172 }
10173
10174
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(palcycles,f))
10175 {
10176 new_return(15);
10177 }
10178
10179
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 12 times.
288 for(int32_t i=0; i<palcycles; i++)
10180 {
10181
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10182 {
10183
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].first,f))
10184 {
10185 new_return(16);
10186 }
10187 828 }
10188
10189
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10190 {
10191
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].count,f))
10192 {
10193 new_return(17);
10194 }
10195 828 }
10196
10197
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10198 {
10199
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].speed,f))
10200 {
10201 new_return(18);
10202 }
10203 828 }
10204 276 }
10205
10206
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10207 {
10208 6 section_size=writesize;
10209 6 }
10210 12 }
10211
10212
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10213 {
10214 char ebuf[80];
10215 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10216 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10217 }
10218
10219 6 new_return(0);
10220 }
10221
10222 6 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10223 {
10224 //these are here to bypass compiler warnings about unused arguments
10225 6 version=version;
10226 6 build=build;
10227 6 start_msgstr=start_msgstr;
10228 6 max_msgstrs=max_msgstrs;
10229
10230 6 dword section_id=ID_STRINGS;
10231 6 dword section_version=V_STRINGS;
10232 6 dword section_cversion=CV_STRINGS;
10233 6 dword section_size = 0;
10234
10235 //section id
10236
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10237 {
10238 new_return(1);
10239 }
10240
10241 //section version info
10242
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10243 {
10244 new_return(2);
10245 }
10246
10247
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10248 {
10249 new_return(3);
10250 }
10251
10252
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10253 {
10254 12 fake_pack_writing=(writecycle==0);
10255
10256 //section size
10257
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10258 {
10259 new_return(4);
10260 }
10261
10262 12 writesize=0;
10263
10264 //finally... section data
10265
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(msg_count,f))
10266 {
10267 return qe_invalid;
10268 }
10269
10270
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 12 times.
314 for(int32_t i=0; i<msg_count; i++)
10271 {
10272 302 int32_t sz = MsgStrings[i].s.size();
10273
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(sz > 8192) sz = 8192;
10274
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(sz, f))
10275 {
10276 return qe_invalid;
10277 }
10278
10279 302 char const* tmpstr = MsgStrings[i].s.c_str();
10280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
302 if (sz > 0)
10281 {
10282
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if (!pfwrite((void*)tmpstr,sz, f))
10283 {
10284 return qe_invalid;
10285 }
10286 302 }
10287
10288
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].nextstring,f))
10289 {
10290 return qe_invalid;
10291 }
10292
10293
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].tile,f))
10294 {
10295 return qe_invalid;
10296 }
10297
10298
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].cset,f))
10299 {
10300 return qe_invalid;
10301 }
10302
10303
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].trans?1:0,f))
10304 {
10305 return qe_invalid;
10306 }
10307
10308
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].font,f))
10309 {
10310 return qe_invalid;
10311 }
10312
10313
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].x,f))
10314 {
10315 return qe_invalid;
10316 }
10317
10318
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].y,f))
10319 {
10320 return qe_invalid;
10321 }
10322
10323
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].w,f))
10324 {
10325 return qe_invalid;
10326 }
10327
10328
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].h,f))
10329 {
10330 return qe_invalid;
10331 }
10332
10333
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].hspace,f))
10334 {
10335 return qe_invalid;
10336 }
10337
10338
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].vspace,f))
10339 {
10340 return qe_invalid;
10341 }
10342
10343
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].stringflags,f))
10344 {
10345 return qe_invalid;
10346 }
10347
10348
2/2
✓ Branch 0 taken 1208 times.
✓ Branch 1 taken 302 times.
1510 for(int32_t q = 0; q < 4; ++q)
10349 {
10350
1/2
✓ Branch 0 taken 1208 times.
✗ Branch 1 not taken.
1208 if(!p_putc(MsgStrings[i].margins[q],f))
10351 {
10352 return qe_invalid;
10353 }
10354 1208 }
10355
10356
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10357 {
10358 return qe_invalid;
10359 }
10360
10361
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_cset,f))
10362 {
10363 return qe_invalid;
10364 }
10365
10366
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_x,f))
10367 {
10368 return qe_invalid;
10369 }
10370
10371
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_y,f))
10372 {
10373 return qe_invalid;
10374 }
10375
10376
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_tw,f))
10377 {
10378 return qe_invalid;
10379 }
10380
10381
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_th,f))
10382 {
10383 return qe_invalid;
10384 }
10385
10386
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_type,f))
10387 {
10388 return qe_invalid;
10389 }
10390
10391
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_color,f))
10392 {
10393 return qe_invalid;
10394 }
10395
10396
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].drawlayer,f))
10397 {
10398 return qe_invalid;
10399 }
10400
10401
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].sfx,f))
10402 {
10403 return qe_invalid;
10404 }
10405
10406
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].listpos,f))
10407 {
10408 return qe_invalid;
10409 }
10410 302 }
10411
10412
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10413 {
10414 6 section_size=writesize;
10415 6 }
10416 12 }
10417
10418
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10419 {
10420 char ebuf[80];
10421 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10422 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10423 }
10424
10425 6 new_return(0);
10426 6 }
10427
10428 int32_t writestrings_text(PACKFILE *f)
10429 {
10430 std::map<int32_t, int32_t> msglistcache;
10431
10432 for(int32_t index = 1; index<msg_count; index++)
10433 {
10434 for(int32_t i=1; i<msg_count; i++)
10435 {
10436 if(MsgStrings[i].listpos==index)
10437 {
10438 msglistcache[index-1]=i;
10439 break;
10440 }
10441 }
10442 }
10443
10444 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10445 {
10446 fake_pack_writing=(writecycle==0);
10447 char ebuf[32];
10448
10449 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10450
10451 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10452 {
10453 return qe_invalid;
10454 }
10455
10456 for(int32_t i=1; i<msg_count; i++)
10457 {
10458 int32_t str = msglistcache[i-1];
10459
10460 if(!str)
10461 continue;
10462
10463 if(MsgStrings[str].nextstring != 0)
10464 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10465 else
10466 sprintf(ebuf,"\n\n___%d___\n", str);
10467
10468 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10469 {
10470 return qe_invalid;
10471 }
10472
10473 encode_msg_str(str);
10474
10475 if(!pfwrite(&msgbuf,(int32_t)strlen(msgbuf),f))
10476 {
10477 return qe_invalid;
10478 }
10479 }
10480 }
10481
10482 new_return(0);
10483 }
10484
10485 1 int32_t writestrings_tsv(PACKFILE *f)
10486 {
10487 1 std::stringstream ss;
10488
10489 int32_t str;
10490
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10491
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){
10492 35 encode_msg_str(str);
10493 35 return msgbuf;
10494 }},
10495
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10496
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10497
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10498
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10499
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10500
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10501
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10502
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10503
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10504
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10505
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10506
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10507
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10508
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10509
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10510
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10511
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10512
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10513
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10514
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10515
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10516
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10517
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10518
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10519 };
10520
10521
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10522 {
10523
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10524
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10525 1 break;
10526
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10527 }
10528
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10529
10530 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10531
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10532
10533
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10534 {
10535 35 str = i;
10536 35 auto& msg = MsgStrings[str];
10537
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10538 {
10539
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10540
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10541
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10542 35 break;
10543
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10544
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10545
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10546 35 }
10547
10548
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10549
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10550 {
10551 return qe_invalid;
10552 }
10553
10554 1 new_return(0);
10555 1 }
10556
10557 std::string parse_msg_str(std::string const& s);
10558
10559 void parse_strings_tsv(std::string tsv)
10560 {
10561 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10562 { "message", [](auto& msg, auto& text){ msg.s = parse_msg_str(text); } },
10563 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10564 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10565 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10566 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10567 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10568 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10569 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10570 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10571 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10572 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10573 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10574 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10575 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10576 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10577 { "margin", [&](auto& msg, auto& text){
10578 std::vector<std::string> strs;
10579 util::split(text, strs, ' ');
10580 if (strs.size() != 4)
10581 throw std::runtime_error("margin field must have 4 components");
10582 msg.margins[0] = std::stoi(strs[0]);
10583 msg.margins[1] = std::stoi(strs[1]);
10584 msg.margins[2] = std::stoi(strs[2]);
10585 msg.margins[3] = std::stoi(strs[3]);
10586 } },
10587 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10588 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10589 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10590 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10591 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10592 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10593 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10594 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10595 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10596 };
10597
10598 std::vector<std::string> rows;
10599 util::split(tsv, rows, '\n');
10600 if (rows.size())
10601 {
10602 std::string last = rows.back();
10603 util::trimstr(last);
10604 if (last.empty())
10605 rows.pop_back();
10606 }
10607 if (rows.size() <= 1)
10608 throw std::runtime_error("missing header row");
10609
10610 std::vector<std::string> columns;
10611 util::split(rows[0], columns, '\t');
10612 for (auto name : columns)
10613 {
10614 if (!fields.contains(name))
10615 throw std::runtime_error(fmt::format("invalid field: {}", name));
10616 }
10617
10618 int start_index = 1;
10619 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10620 start_index += 1;
10621
10622 int num_strings = rows.size() - start_index + 1;
10623 if (num_strings > MAXMSGS-1)
10624 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10625
10626 std::vector<MsgStr> msgs;
10627 msgs.reserve(num_strings);
10628 for (int i = start_index; i < rows.size(); i++)
10629 {
10630 std::vector<std::string> strs;
10631 util::split(rows[i], strs, '\t');
10632 if (strs.size() != columns.size())
10633 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10634
10635 int j = 0;
10636 auto& msg = msgs.emplace_back();
10637 for (auto& name : columns)
10638 {
10639 auto& fn = fields[name];
10640 try
10641 {
10642 fn(msg, strs[j++]);
10643 }
10644 catch (std::exception& ex)
10645 {
10646 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10647 }
10648 }
10649 }
10650
10651 init_msgstrings(0, msgs.size());
10652 for (int i = 0; i < msgs.size(); i++)
10653 MsgStrings[i + 1] = msgs[i];
10654 msg_count = msgs.size();
10655 msglistcache.clear();
10656 }
10657
10658 bool isblanktile(tiledata *buf, int32_t i);
10659 6 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10660 {
10661 //these are here to bypass compiler warnings about unused arguments
10662 6 version=version;
10663 6 build=build;
10664
10665 int32_t tiles_used;
10666 6 dword section_id=ID_TILES;
10667 6 dword section_version=V_TILES;
10668 6 dword section_cversion=CV_TILES;
10669 6 al_trace("Counting tiles used\n");
10670 6 tiles_used = count_tiles(newtilebuf)-start_tile;
10671
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, max_tiles);
10672
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10673 6 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10674 6 dword section_size = 0;
10675
10676 //section id
10677
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10678 {
10679 new_return(1);
10680 }
10681
10682 //section version info
10683
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10684 {
10685 new_return(2);
10686 }
10687
10688
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10689 {
10690 new_return(3);
10691 }
10692
10693
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10694 {
10695 12 fake_pack_writing=(writecycle==0);
10696
10697 //section size
10698
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10699 {
10700 new_return(4);
10701 }
10702
10703 12 writesize=0;
10704
10705 //finally... section data
10706 12 tiles_used=count_tiles(newtilebuf)-start_tile;
10707
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, max_tiles);
10708
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10709
10710
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(tiles_used,f))
10711 {
10712 new_return(5);
10713 }
10714
10715
2/2
✓ Branch 0 taken 448054 times.
✓ Branch 1 taken 12 times.
448066 for(int32_t i=0; i<tiles_used; ++i)
10716 {
10717
2/2
✓ Branch 0 taken 238750 times.
✓ Branch 1 taken 209304 times.
448054 if(isblanktile(newtilebuf, start_tile+i))
10718 {
10719
1/2
✓ Branch 0 taken 238750 times.
✗ Branch 1 not taken.
238750 if(!p_putc(0,f))
10720 new_return(8);
10721 238750 }
10722 else
10723 {
10724 209304 int format = newtilebuf[start_tile+i].format;
10725
1/2
✓ Branch 0 taken 209304 times.
✗ Branch 1 not taken.
209304 if(!p_putc(format,f))
10726 {
10727 new_return(6);
10728 }
10729
10730
2/2
✓ Branch 0 taken 207706 times.
✓ Branch 1 taken 1598 times.
209304 if (format == tf4Bit)
10731 {
10732 byte temp_tile[128];
10733 207706 byte *di = temp_tile;
10734 207706 byte *src = newtilebuf[start_tile+i].data;
10735
2/2
✓ Branch 0 taken 26586368 times.
✓ Branch 1 taken 207706 times.
26794074 for (int32_t si=0; si<256; si+=2)
10736 {
10737 26586368 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10738 26586368 ++di;
10739 26586368 }
10740
1/2
✓ Branch 0 taken 207706 times.
✗ Branch 1 not taken.
207706 if (!pfwrite(temp_tile,128,f))
10741 {
10742 new_return(7);
10743 }
10744 207706 }
10745
1/2
✓ Branch 0 taken 1598 times.
✗ Branch 1 not taken.
1598 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10746 {
10747 new_return(7);
10748 }
10749 }
10750 448054 }
10751
10752
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10753 {
10754 6 section_size=writesize;
10755 6 }
10756 12 }
10757
10758
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10759 {
10760 char ebuf[80];
10761 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10762 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10763 }
10764
10765 6 new_return(0);
10766 }
10767
10768 /* MIDI Format
10769 section_id LONG
10770 section_version WORD
10771 section_cversion WORD
10772 section_size LONG
10773 midi_flags 32 Byte ? BITFIELD[252]
10774
10775 [
10776 title 36
10777 start 4
10778 loop_start 4
10779 loop_end 4
10780 loop 2
10781 volume 2
10782 midi *
10783 ]
10784
10785 */
10786
10787 6 int32_t writemidis(PACKFILE *f)
10788 {
10789 6 dword section_id=ID_MIDIS;
10790 6 dword section_version=V_MIDIS;
10791 6 dword section_cversion=CV_MIDIS;
10792 6 dword section_size = 0;
10793
10794 //section id
10795
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10796 {
10797 new_return(1);
10798 }
10799
10800 //section version info
10801
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10802 {
10803 new_return(2);
10804 }
10805
10806
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10807 {
10808 new_return(3);
10809 }
10810
10811
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10812 {
10813 12 fake_pack_writing=(writecycle==0);
10814
10815 //section size
10816
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10817 {
10818 new_return(4);
10819 }
10820
10821 12 writesize=0;
10822
10823 //finally... section data
10824
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10825 {
10826 new_return(5);
10827 }
10828
10829
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10830 {
10831
2/2
✓ Branch 0 taken 2964 times.
✓ Branch 1 taken 60 times.
3024 if(get_bit(midi_flags,i))
10832 {
10833
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10834 {
10835 new_return(6);
10836 }
10837
10838
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].start,f))
10839 {
10840 new_return(7);
10841 }
10842
10843
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_start,f))
10844 {
10845 new_return(8);
10846 }
10847
10848
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_end,f))
10849 {
10850 new_return(9);
10851 }
10852
10853
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].loop,f))
10854 {
10855 new_return(10);
10856 }
10857
10858
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].volume,f))
10859 {
10860 new_return(11);
10861 }
10862
10863
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10864 {
10865 new_return(12);
10866 }
10867
10868 60 byte format = MFORMAT_MIDI;
10869
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&format, sizeof(format),f))
10870 {
10871 new_return(13);
10872 }
10873
10874
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if (!write_midi(customtunes[i].data, f)) new_return(14);
10875 60 }
10876 3024 }
10877
10878
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10879 {
10880 6 section_size=writesize;
10881 6 }
10882 12 }
10883
10884
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10885 {
10886 char ebuf[80];
10887 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10888 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10889 }
10890
10891 6 new_return(0);
10892 }
10893
10894 6 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10895 {
10896 6 dword section_id=ID_CHEATS;
10897 6 dword section_version=V_CHEATS;
10898 6 dword section_cversion=CV_CHEATS;
10899 6 dword section_size = 0;
10900
10901 //section id
10902
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10903 {
10904 new_return(1);
10905 }
10906
10907 //section version info
10908
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10909 {
10910 new_return(2);
10911 }
10912
10913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10914 {
10915 new_return(3);
10916 }
10917
10918
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10919 {
10920 12 fake_pack_writing=(writecycle==0);
10921
10922 //section size
10923
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10924 {
10925 new_return(4);
10926 }
10927
10928 12 writesize=0;
10929
10930 //finally... section data
10931
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10932 {
10933 new_return(5);
10934 }
10935
10936
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(Header->data_flags[ZQ_CHEATS2])
10937 {
10938
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zcheats.flags,f))
10939 {
10940 new_return(6);
10941 }
10942
10943
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10944 {
10945 new_return(7);
10946 }
10947 12 }
10948
10949
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10950 {
10951 6 section_size=writesize;
10952 6 }
10953 12 }
10954
10955
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10956 {
10957 char ebuf[80];
10958 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10959 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10960 }
10961
10962 6 new_return(0);
10963 }
10964
10965 6 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10966 {
10967 //these are here to bypass compiler warnings about unused arguments
10968 6 Header=Header;
10969
10970 6 dword section_id=ID_GUYS;
10971 6 dword section_version=V_GUYS;
10972 6 dword section_cversion=CV_GUYS;
10973 6 dword section_size=0;
10974
10975 //section id
10976
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10977 {
10978 new_return(1);
10979 }
10980
10981 //section version info
10982
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10983 {
10984 new_return(2);
10985 }
10986
10987
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
10988 {
10989 new_return(3);
10990 }
10991
10992
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10993 {
10994 12 fake_pack_writing=(writecycle==0);
10995
10996 //section size
10997
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10998 {
10999 new_return(4);
11000 }
11001
11002 12 writesize=0;
11003
11004 //finally... section data
11005
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11006 {
11007
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite((char *)guy_string[i], 64, f))
11008 {
11009 new_return(5);
11010 }
11011 6144 }
11012
11013
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11014 {
11015 6144 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11016 6144 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11017
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(flags1, f))
11018 {
11019 new_return(6);
11020 }
11021
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(flags2, f))
11022 {
11023 new_return(7);
11024 }
11025
11026
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tile,f))
11027 {
11028 new_return(8);
11029 }
11030
11031
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].width,f))
11032 {
11033 new_return(9);
11034 }
11035
11036
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].height,f))
11037 {
11038 new_return(10);
11039 }
11040
11041
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].s_tile,f))
11042 {
11043 new_return(11);
11044 }
11045
11046
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_width,f))
11047 {
11048 new_return(12);
11049 }
11050
11051
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_height,f))
11052 {
11053 new_return(13);
11054 }
11055
11056
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].e_tile,f))
11057 {
11058 new_return(14);
11059 }
11060
11061
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_width,f))
11062 {
11063 new_return(15);
11064 }
11065
11066
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_height,f))
11067 {
11068 new_return(16);
11069 }
11070
11071
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hp,f))
11072 {
11073 new_return(17);
11074 }
11075
11076
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].family,f))
11077 {
11078 new_return(18);
11079 }
11080
11081
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].cset,f))
11082 {
11083 new_return(19);
11084 }
11085
11086
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].anim,f))
11087 {
11088 new_return(20);
11089 }
11090
11091
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_anim,f))
11092 {
11093 new_return(21);
11094 }
11095
11096
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].frate,f))
11097 {
11098 new_return(22);
11099 }
11100
11101
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_frate,f))
11102 {
11103 new_return(23);
11104 }
11105
11106
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].dp,f))
11107 {
11108 new_return(24);
11109 }
11110
11111
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].wdp,f))
11112 {
11113 new_return(25);
11114 }
11115
11116
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weapon,f))
11117 {
11118 new_return(26);
11119 }
11120
11121
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].rate,f))
11122 {
11123 new_return(27);
11124 }
11125
11126
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hrate,f))
11127 {
11128 new_return(28);
11129 }
11130
11131
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].step,f))
11132 {
11133 new_return(29);
11134 }
11135
11136
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].homing,f))
11137 {
11138 new_return(30);
11139 }
11140
11141
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].grumble,f))
11142 {
11143 new_return(31);
11144 }
11145
11146
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].item_set,f))
11147 {
11148 new_return(32);
11149 }
11150
11151
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[0], f))
11152 {
11153 new_return(33);
11154 }
11155
11156
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[1],f))
11157 {
11158 new_return(34);
11159 }
11160
11161
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[2],f))
11162 {
11163 new_return(35);
11164 }
11165
11166
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[3],f))
11167 {
11168 new_return(36);
11169 }
11170
11171
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[4],f))
11172 {
11173 new_return(37);
11174 }
11175
11176
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[5],f))
11177 {
11178 new_return(38);
11179 }
11180
11181
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[6],f))
11182 {
11183 new_return(39);
11184 }
11185
11186
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[7],f))
11187 {
11188 new_return(40);
11189 }
11190
11191
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[8],f))
11192 {
11193 new_return(41);
11194 }
11195
11196
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[9],f))
11197 {
11198 new_return(42);
11199 }
11200
11201
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bgsfx,f))
11202 {
11203 new_return(43);
11204 }
11205
11206
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bosspal,f))
11207 {
11208 new_return(44);
11209 }
11210
11211
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].extend,f))
11212 {
11213 new_return(45);
11214 }
11215
11216
2/2
✓ Branch 0 taken 116736 times.
✓ Branch 1 taken 6144 times.
122880 for(int32_t j=0; j < edefLAST; j++)
11217 {
11218
1/2
✓ Branch 0 taken 116736 times.
✗ Branch 1 not taken.
116736 if(!p_putc(guysbuf[i].defense[j],f))
11219 {
11220 new_return(46);
11221 }
11222 116736 }
11223
11224
4/6
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4096 times.
✓ Branch 3 taken 2048 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4096 times.
6144 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11225 {
11226 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11227 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11228 //Force SFX_HIT here.
11229
11230 }
11231
11232
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].hitsfx,f))
11233 {
11234 new_return(47);
11235 }
11236
11237
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].deadsfx,f))
11238 {
11239 new_return(48);
11240 }
11241
11242
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[10],f))
11243 {
11244 new_return(49);
11245 }
11246
11247
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[11],f))
11248 {
11249 new_return(50);
11250 }
11251
11252 //New 2.6 defences
11253
2/2
✓ Branch 0 taken 135168 times.
✓ Branch 1 taken 6144 times.
141312 for(int32_t j=edefLAST; j < edefLAST255; j++)
11254 {
11255
1/2
✓ Branch 0 taken 135168 times.
✗ Branch 1 not taken.
135168 if(!p_putc(guysbuf[i].defense[j],f))
11256 {
11257 new_return(51);
11258 }
11259 135168 }
11260
11261 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11262
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].txsz,f))
11263 {
11264 new_return(52);
11265 }
11266
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tysz,f))
11267 {
11268 new_return(53);
11269 }
11270
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxsz,f))
11271 {
11272 new_return(54);
11273 }
11274
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hysz,f))
11275 {
11276 new_return(55);
11277 }
11278
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hzsz,f))
11279 {
11280 new_return(56);
11281 }
11282 // These are not fixed types, but ints, so they are safe to use here.
11283
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxofs,f))
11284 {
11285 new_return(57);
11286 }
11287
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hyofs,f))
11288 {
11289 new_return(58);
11290 }
11291
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].xofs,f))
11292 {
11293 new_return(59);
11294 }
11295
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].yofs,f))
11296 {
11297 new_return(60);
11298 }
11299
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].zofs,f))
11300 {
11301 new_return(61);
11302 }
11303
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].wpnsprite,f))
11304 {
11305 new_return(62);
11306 }
11307
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].SIZEflags,f))
11308 {
11309 new_return(63);
11310 }
11311
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozentile,f))
11312 {
11313 new_return(64);
11314 }
11315
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozencset,f))
11316 {
11317 new_return(65);
11318 }
11319
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozenclock,f))
11320 {
11321 new_return(66);
11322 }
11323
11324
2/2
✓ Branch 0 taken 61440 times.
✓ Branch 1 taken 6144 times.
67584 for ( int32_t q = 0; q < 10; q++ )
11325 {
11326
1/2
✓ Branch 0 taken 61440 times.
✗ Branch 1 not taken.
61440 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11327 {
11328 new_return(67);
11329 }
11330 61440 }
11331
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].firesfx,f))
11332 {
11333 new_return(68);
11334 }
11335 //misc 16->31
11336
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[15],f))
11337 {
11338 new_return(69);
11339 }
11340
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[16],f))
11341 {
11342 new_return(70);
11343 }
11344
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[17],f))
11345 {
11346 new_return(71);
11347 }
11348
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[18],f))
11349 {
11350 new_return(72);
11351 }
11352
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[19],f))
11353 {
11354 new_return(73);
11355 }
11356
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[20],f))
11357 {
11358 new_return(74);
11359 }
11360
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[21],f))
11361 {
11362 new_return(75);
11363 }
11364
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[22],f))
11365 {
11366 new_return(76);
11367 }
11368
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[23],f))
11369 {
11370 new_return(77);
11371 }
11372
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[24],f))
11373 {
11374 new_return(78);
11375 }
11376
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[25],f))
11377 {
11378 new_return(79);
11379 }
11380
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[26],f))
11381 {
11382 new_return(80);
11383 }
11384
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[27],f))
11385 {
11386 new_return(81);
11387 }
11388
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[28],f))
11389 {
11390 new_return(82);
11391 }
11392
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[29],f))
11393 {
11394 new_return(83);
11395 }
11396
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[30],f))
11397 {
11398 new_return(84);
11399 }
11400
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[31],f))
11401 {
11402 new_return(85);
11403 }
11404
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11405 {
11406
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].movement[q],f))
11407 {
11408 new_return(86);
11409 }
11410 196608 }
11411
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11412 {
11413
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11414 {
11415 new_return(87);
11416 }
11417 196608 }
11418
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].script,f))
11419 {
11420 new_return(88);
11421 }
11422
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11423 {
11424
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].initD[q],f))
11425 {
11426 new_return(89);
11427 }
11428 49152 }
11429
2/2
✓ Branch 0 taken 12288 times.
✓ Branch 1 taken 6144 times.
18432 for ( int32_t q = 0; q < 2; q++ )
11430 {
11431
1/2
✓ Branch 0 taken 12288 times.
✗ Branch 1 not taken.
12288 if(!p_iputl(guysbuf[i].initA[q],f))
11432 {
11433 new_return(90);
11434 }
11435 12288 }
11436
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].editorflags,f))
11437 {
11438 new_return(91);
11439 }
11440 //somehow forgot these in the older builds -Z
11441
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[12],f))
11442 {
11443 new_return(92);
11444 }
11445
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[13],f))
11446 {
11447 new_return(93);
11448 }
11449
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].attributes[14],f))
11450 {
11451 new_return(94);
11452 }
11453
11454 //Enemy Editor InitD[] labels
11455
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11456 {
11457
2/2
✓ Branch 0 taken 3194880 times.
✓ Branch 1 taken 49152 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11458 {
11459
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11460 {
11461 new_return(95);
11462 }
11463 3194880 }
11464
2/2
✓ Branch 0 taken 3194880 times.
✓ Branch 1 taken 49152 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11465 {
11466
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
11467 {
11468 new_return(96);
11469 }
11470 3194880 }
11471 49152 }
11472
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weaponscript,f))
11473 {
11474 new_return(97);
11475 }
11476 //eweapon initD
11477
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11478 {
11479
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
11480 {
11481 new_return(98);
11482 }
11483 49152 }
11484
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].moveflags,f))
11485 new_return(99);
11486
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_shadow,f))
11487 new_return(100);
11488
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_death,f))
11489 new_return(101);
11490
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_spawn,f))
11491 new_return(102);
11492
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_putc(guysbuf[i].wunblockable, f))
11493 new_return(103);
11494
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].wmoveflags, f))
11495 new_return(104);
11496
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weapoverrideFLAGS, f))
11497 new_return(105);
11498
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_tilew, f))
11499 new_return(106);
11500
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_tileh, f))
11501 new_return(107);
11502
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hxsz, f))
11503 new_return(108);
11504
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hysz, f))
11505 new_return(109);
11506
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hzsz, f))
11507 new_return(110);
11508
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hxofs, f))
11509 new_return(111);
11510
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_hyofs, f))
11511 new_return(112);
11512
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_xofs, f))
11513 new_return(113);
11514
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].weap_yofs, f))
11515 new_return(114);
11516
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(guysbuf[i].wstep, f))
11517 new_return(115);
11518
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 6144 times.
36864 for(int32_t q = 0; q < WPNSPR_MAX; ++q)
11519 {
11520
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if (!p_iputw(guysbuf[i].burnsprs[q], f))
11521 new_return(116 + q);
11522
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if (!p_iputw(guysbuf[i].light_rads[q], f))
11523 new_return(116 + WPNSPR_MAX + q);
11524 30720 }
11525
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_putc(guysbuf[i].specialsfx, f))
11526 new_return(126)
11527 6144 }
11528
11529
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11530 {
11531 6 section_size=writesize;
11532 6 }
11533 12 }
11534
11535
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11536 {
11537 char ebuf[80];
11538 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11539 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11540 }
11541
11542 6 new_return(0);
11543 6 }
11544
11545 6 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11546 {
11547 //these are here to bypass compiler warnings about unused arguments
11548 6 Header=Header;
11549
11550 6 dword section_id=ID_HEROSPRITES;
11551 6 dword section_version=V_HEROSPRITES;
11552 6 dword section_cversion=CV_HEROSPRITES;
11553 6 dword section_size=0;
11554
11555 //section id
11556
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11557 {
11558 new_return(1);
11559 }
11560
11561 //section version info
11562
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11563 {
11564 new_return(2);
11565 }
11566
11567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11568 {
11569 new_return(3);
11570 }
11571
11572
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11573 {
11574 12 fake_pack_writing=(writecycle==0);
11575
11576 //section size
11577
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11578 {
11579 new_return(4);
11580 }
11581
11582 12 writesize=0;
11583
11584 //finally... section data
11585
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11586 {
11587
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(walkspr[i][spr_tile],f))
11588 {
11589 new_return(5);
11590 }
11591
11592
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_flip],f))
11593 {
11594 new_return(5);
11595 }
11596
11597
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_extend],f))
11598 {
11599 new_return(5);
11600 }
11601 48 }
11602
11603
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11604 {
11605
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stabspr[i][spr_tile],f))
11606 {
11607 new_return(6);
11608 }
11609
11610
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_flip],f))
11611 {
11612 new_return(6);
11613 }
11614
11615
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_extend],f))
11616 {
11617 new_return(6);
11618 }
11619 48 }
11620
11621
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11622 {
11623
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashspr[i][spr_tile],f))
11624 {
11625 new_return(7);
11626 }
11627
11628
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_flip],f))
11629 {
11630 new_return(7);
11631 }
11632
11633
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_extend],f))
11634 {
11635 new_return(7);
11636 }
11637 48 }
11638
11639
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11640 {
11641
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(floatspr[i][spr_tile],f))
11642 {
11643 new_return(8);
11644 }
11645
11646
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_flip],f))
11647 {
11648 new_return(8);
11649 }
11650
11651
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_extend],f))
11652 {
11653 new_return(8);
11654 }
11655 48 }
11656
11657
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11658 {
11659
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(swimspr[i][spr_tile],f))
11660 {
11661 new_return(8);
11662 }
11663
11664
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_flip],f))
11665 {
11666 new_return(8);
11667 }
11668
11669
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_extend],f))
11670 {
11671 new_return(8);
11672 }
11673 48 }
11674
11675
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11676 {
11677
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(divespr[i][spr_tile],f))
11678 {
11679 new_return(9);
11680 }
11681
11682
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_flip],f))
11683 {
11684 new_return(9);
11685 }
11686
11687
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_extend],f))
11688 {
11689 new_return(9);
11690 }
11691 48 }
11692
11693
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11694 {
11695
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(poundspr[i][spr_tile],f))
11696 {
11697 new_return(10);
11698 }
11699
11700
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_flip],f))
11701 {
11702 new_return(10);
11703 }
11704
11705
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_extend],f))
11706 {
11707 new_return(10);
11708 }
11709 48 }
11710
11711
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(castingspr[spr_tile],f))
11712 {
11713 new_return(11);
11714 }
11715
11716
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_flip],f))
11717 {
11718 new_return(11);
11719 }
11720
11721
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_extend],f))
11722 {
11723 new_return(11);
11724 }
11725
11726
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for(int32_t i=0; i<2; i++)
11727 {
11728
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 for(int32_t j=0; j<spr_holdmax; j++)
11729 {
11730
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(holdspr[i][j][spr_tile],f))
11731 {
11732 new_return(12);
11733 }
11734
11735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11736 {
11737 new_return(12);
11738 }
11739
11740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11741 {
11742 new_return(12);
11743 }
11744 72 }
11745 24 }
11746
11747
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11748 {
11749
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(jumpspr[i][spr_tile],f))
11750 {
11751 new_return(13);
11752 }
11753
11754
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11755 {
11756 new_return(13);
11757 }
11758
11759
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11760 {
11761 new_return(13);
11762 }
11763 48 }
11764
11765
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11766 {
11767
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(chargespr[i][spr_tile],f))
11768 {
11769 new_return(13);
11770 }
11771
11772
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_flip],f))
11773 {
11774 new_return(13);
11775 }
11776
11777
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_extend],f))
11778 {
11779 new_return(13);
11780 }
11781 48 }
11782
11783
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)zinit.hero_swim_speed,f))
11784 {
11785 new_return(14);
11786 }
11787
11788 //{ V_HEROSPRITES >= 7
11789
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11790 {
11791
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozenspr[q][spr_tile],f))
11792 new_return(15);
11793
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11794 new_return(15);
11795
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11796 new_return(15);
11797 48 }
11798
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11799 {
11800
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11801 new_return(15);
11802
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11803 new_return(15);
11804
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11805 new_return(15);
11806 48 }
11807
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11808 {
11809
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfirespr[q][spr_tile],f))
11810 new_return(15);
11811
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11812 new_return(15);
11813
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11814 new_return(15);
11815 48 }
11816
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11817 {
11818
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11819 new_return(15);
11820
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11821 new_return(15);
11822
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11823 new_return(15);
11824 48 }
11825
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11826 {
11827
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(diggingspr[q][spr_tile],f))
11828 new_return(15);
11829
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11830 new_return(15);
11831
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11832 new_return(15);
11833 48 }
11834
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11835 {
11836
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingrodspr[q][spr_tile],f))
11837 new_return(15);
11838
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11839 new_return(15);
11840
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11841 new_return(15);
11842 48 }
11843
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11844 {
11845
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingcanespr[q][spr_tile],f))
11846 new_return(15);
11847
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11848 new_return(15);
11849
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11850 new_return(15);
11851 48 }
11852
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11853 {
11854
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pushingspr[q][spr_tile],f))
11855 new_return(15);
11856
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11857 new_return(15);
11858
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11859 new_return(15);
11860 48 }
11861
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11862 {
11863
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingspr[q][spr_tile],f))
11864 new_return(15);
11865
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11866 new_return(15);
11867
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11868 new_return(15);
11869
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11870 new_return(15);
11871 48 }
11872
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11873 {
11874
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11875 new_return(15);
11876
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11877 new_return(15);
11878
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11879 new_return(15);
11880 48 }
11881
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11882 {
11883
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunnedspr[q][spr_tile],f))
11884 new_return(15);
11885
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11886 new_return(15);
11887
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11888 new_return(15);
11889 48 }
11890
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11891 {
11892
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11893 new_return(15);
11894
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11895 new_return(15);
11896
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11897 new_return(15);
11898 48 }
11899
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11900 {
11901
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowningspr[q][spr_tile],f))
11902 new_return(15);
11903
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11904 new_return(15);
11905
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11906 new_return(15);
11907 48 }
11908
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11909 {
11910
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11911 new_return(15);
11912
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11913 new_return(15);
11914
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11915 new_return(15);
11916 48 }
11917
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11918 {
11919
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(fallingspr[q][spr_tile],f))
11920 new_return(15);
11921
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11922 new_return(15);
11923
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11924 new_return(15);
11925 48 }
11926
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11927 {
11928
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shockedspr[q][spr_tile],f))
11929 new_return(15);
11930
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11931 new_return(15);
11932
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11933 new_return(15);
11934 48 }
11935
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11936 {
11937
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11938 new_return(15);
11939
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11940 new_return(15);
11941
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11942 new_return(15);
11943 48 }
11944
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11945 {
11946
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pullswordspr[q][spr_tile],f))
11947 new_return(15);
11948
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11949 new_return(15);
11950
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11951 new_return(15);
11952 48 }
11953
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11954 {
11955
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(readingspr[q][spr_tile],f))
11956 new_return(15);
11957
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_flip],f))
11958 new_return(15);
11959
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_extend],f))
11960 new_return(15);
11961 48 }
11962
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11963 {
11964
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slash180spr[q][spr_tile],f))
11965 new_return(15);
11966
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11967 new_return(15);
11968
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11969 new_return(15);
11970 48 }
11971
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11972 {
11973
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11974 new_return(15);
11975
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11976 new_return(15);
11977
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11978 new_return(15);
11979 48 }
11980
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11981 {
11982
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(dashspr[q][spr_tile],f))
11983 new_return(15);
11984
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_flip],f))
11985 new_return(15);
11986
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_extend],f))
11987 new_return(15);
11988 48 }
11989
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11990 {
11991
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(bonkspr[q][spr_tile],f))
11992 new_return(15);
11993
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11994 new_return(15);
11995
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11996 new_return(15);
11997 48 }
11998
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11999 {
12000
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(medallionsprs[q][spr_tile],f))
12001 new_return(15);
12002
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
12003 new_return(15);
12004
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12005 new_return(15);
12006 36 }
12007
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12008 {
12009
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimspr[q][spr_tile],f))
12010 new_return(16);
12011
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12012 new_return(16);
12013
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12014 new_return(16);
12015 48 }
12016
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12017 {
12018
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12019 new_return(17);
12020
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12021 new_return(17);
12022
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12023 new_return(17);
12024 48 }
12025
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12026 {
12027
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12028 new_return(17);
12029
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12030 new_return(17);
12031
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12032 new_return(17);
12033 48 }
12034
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12035 {
12036
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12037 new_return(17);
12038
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12039 new_return(17);
12040
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12041 new_return(17);
12042 48 }
12043
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12044 {
12045
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12046 new_return(18);
12047
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12048 new_return(18);
12049
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12050 new_return(18);
12051 48 }
12052
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12053 {
12054
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(hammeroffsets[q],f))
12055 new_return(19);
12056 48 }
12057
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q)
12058 {
12059
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12060 new_return(20);
12061
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12062 new_return(20);
12063
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12064 new_return(20);
12065 36 }
12066
12067
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12068 {
12069 new_return(21);
12070 }
12071
12072
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12073 {
12074 new_return(21);
12075 }
12076
12077
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12078 {
12079 new_return(21);
12080 }
12081
12082
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12083 {
12084
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12085 new_return(22);
12086
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12087 new_return(22);
12088
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12089 new_return(22);
12090 48 }
12091
12092
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
12093 {
12094
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(revslashspr[i][spr_tile],f))
12095 {
12096 new_return(23);
12097 }
12098
12099
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12100 {
12101 new_return(23);
12102 }
12103
12104
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12105 {
12106 new_return(23);
12107 }
12108 48 }
12109
12110
12111
2/2
✓ Branch 0 taken 1752 times.
✓ Branch 1 taken 12 times.
1764 for (int32_t q = 0; q < wMax; q++) // Player defense values
12112 {
12113
1/2
✓ Branch 0 taken 1752 times.
✗ Branch 1 not taken.
1752 if (!p_putc(hero_defence[q], f))
12114 new_return(15);
12115 1752 }
12116 //}
12117
12118
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12119 {
12120 6 section_size=writesize;
12121 6 }
12122 12 }
12123
12124 //More data will come here
12125
12126
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12127 {
12128 char ebuf[80];
12129 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12130 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12131 }
12132
12133 6 new_return(0);
12134 }
12135
12136 6 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12137 {
12138 6 dword section_id=ID_SUBSCREEN;
12139 6 dword section_version=V_SUBSCREEN;
12140 6 dword section_cversion=CV_SUBSCREEN;
12141 6 dword section_size=0;
12142
12143 //section id
12144
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12145 {
12146 new_return(1);
12147 }
12148
12149 //section version info
12150
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12151 {
12152 new_return(2);
12153 }
12154
12155
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12156 {
12157 new_return(3);
12158 }
12159
12160
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12161 {
12162 12 fake_pack_writing=(writecycle==0);
12163
12164 //section size
12165
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12166 {
12167 new_return(4);
12168 }
12169
12170 12 writesize=0;
12171
12172 12 byte sz = subscreens_active.size();
12173
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12174 new_return(5);
12175
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 12 times.
78 for(int32_t i=0; i<sz; i++)
12176 {
12177 66 int32_t ret = subscreens_active[i].write(f);
12178 66 fake_pack_writing=(writecycle==0);
12179
12180
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 if(ret!=0)
12181 new_return(ret);
12182 66 }
12183
12184 12 sz = subscreens_passive.size();
12185
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12186 new_return(5);
12187
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 12 times.
62 for(int32_t i=0; i<sz; i++)
12188 {
12189 50 int32_t ret = subscreens_passive[i].write(f);
12190 50 fake_pack_writing=(writecycle==0);
12191
12192
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 if(ret!=0)
12193 new_return(ret);
12194 50 }
12195
12196 12 sz = subscreens_overlay.size();
12197
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12198 new_return(5);
12199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for(int32_t i=0; i<sz; i++)
12200 {
12201 int32_t ret = subscreens_overlay[i].write(f);
12202 fake_pack_writing=(writecycle==0);
12203
12204 if(ret!=0)
12205 new_return(ret);
12206 }
12207
12208
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12209 {
12210 6 section_size=writesize;
12211 6 }
12212 12 }
12213
12214
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12215 {
12216 char ebuf[80];
12217 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12218 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12219 }
12220
12221 6 new_return(0);
12222 6 }
12223
12224 extern script_data *ffscripts[NUMSCRIPTFFC];
12225 extern script_data *itemscripts[NUMSCRIPTITEM];
12226 extern script_data *guyscripts[NUMSCRIPTGUYS];
12227 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12228 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12229 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12230 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12231 extern script_data *playerscripts[NUMSCRIPTPLAYER];
12232 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12233 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12234 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12235 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12236 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12237
12238 6 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12239 {
12240 6 dword section_id = ID_FFSCRIPT;
12241 6 dword section_version = V_FFSCRIPT;
12242 6 dword section_cversion = CV_FFSCRIPT;
12243 6 dword section_size = 0;
12244 6 dword zasmmeta_version = METADATA_V;
12245 6 byte numscripts = 0;
12246 6 numscripts = numscripts; //to avoid unused variables warnings
12247
12248 //section id
12249
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12250 {
12251 new_return(1);
12252 }
12253
12254 //section version info
12255
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12256 {
12257 new_return(2);
12258 }
12259
12260
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12261 {
12262 new_return(3);
12263 }
12264
12265
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12266 {
12267 new_return(4);
12268 }
12269
12270
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12271 {
12272 12 fake_pack_writing=(writecycle==0);
12273
12274 //section size
12275
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12276 {
12277 new_return(5);
12278 }
12279
12280 12 writesize=0;
12281
12282
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12283 {
12284 6144 int32_t ret = write_one_ffscript(f, Header, i, &ffscripts[i]);
12285 6144 fake_pack_writing=(writecycle==0);
12286
12287
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12288 {
12289 new_return(ret);
12290 }
12291 6144 }
12292
12293
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12294 {
12295 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemscripts[i]);
12296 3072 fake_pack_writing=(writecycle==0);
12297
12298
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12299 {
12300 new_return(ret);
12301 }
12302 3072 }
12303
12304
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12305 {
12306 3072 int32_t ret = write_one_ffscript(f, Header, i, &guyscripts[i]);
12307 3072 fake_pack_writing=(writecycle==0);
12308
12309
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12310 {
12311 new_return(ret);
12312 }
12313 3072 }
12314
12315
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12316
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12317 {
12318 3072 int32_t ret = write_one_ffscript(f, Header, i, &fake);
12319 3072 fake_pack_writing=(writecycle==0);
12320
12321
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12322 {
12323 new_return(ret);
12324 }
12325 3072 }
12326
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12327
12328
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12329 {
12330 3072 int32_t ret = write_one_ffscript(f, Header, i, &screenscripts[i]);
12331 3072 fake_pack_writing=(writecycle==0);
12332
12333
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12334 {
12335 new_return(ret);
12336 }
12337 3072 }
12338
12339
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12340 {
12341 96 int32_t ret = write_one_ffscript(f, Header, i, &globalscripts[i]);
12342 96 fake_pack_writing=(writecycle==0);
12343
12344
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12345 {
12346 new_return(ret);
12347 }
12348 96 }
12349
12350
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTPLAYER; i++)
12351 {
12352 60 int32_t ret = write_one_ffscript(f, Header, i, &playerscripts[i]);
12353 60 fake_pack_writing=(writecycle==0);
12354
12355
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12356 {
12357 new_return(ret);
12358 }
12359 60 }
12360
12361
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12362 {
12363 3072 int32_t ret = write_one_ffscript(f, Header, i, &lwpnscripts[i]);
12364 3072 fake_pack_writing=(writecycle==0);
12365
12366
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12367 {
12368 new_return(ret);
12369 }
12370 3072 }
12371
12372
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12373 {
12374 3072 int32_t ret = write_one_ffscript(f, Header, i, &ewpnscripts[i]);
12375 3072 fake_pack_writing=(writecycle==0);
12376
12377
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12378 {
12379 new_return(ret);
12380 }
12381 3072 }
12382
12383
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12384 {
12385 3072 int32_t ret = write_one_ffscript(f, Header, i, &dmapscripts[i]);
12386 3072 fake_pack_writing=(writecycle==0);
12387
12388
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12389 {
12390 new_return(ret);
12391 }
12392 3072 }
12393
12394
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12395 {
12396 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemspritescripts[i]);
12397 3072 fake_pack_writing=(writecycle==0);
12398
12399
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12400 {
12401 new_return(ret);
12402 }
12403 3072 }
12404
12405
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12406 {
12407 6144 int32_t ret = write_one_ffscript(f, Header, i, &comboscripts[i]);
12408 6144 fake_pack_writing=(writecycle==0);
12409
12410
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12411 {
12412 new_return(ret);
12413 }
12414 6144 }
12415
12416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12417 {
12418 new_return(2000);
12419 }
12420
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12421 {
12422 6144 int32_t ret = write_one_ffscript(f, Header, i, &genericscripts[i]);
12423 6144 fake_pack_writing=(writecycle==0);
12424
12425
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12426 {
12427 new_return(ret);
12428 }
12429 6144 }
12430
12431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12432 {
12433 new_return(2001);
12434 }
12435
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12436 {
12437 3072 int32_t ret = write_one_ffscript(f, Header, i, &subscreenscripts[i]);
12438 3072 fake_pack_writing=(writecycle==0);
12439
12440
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12441 {
12442 new_return(ret);
12443 }
12444 3072 }
12445
12446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12447 {
12448 new_return(2001);
12449 }
12450
12451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12452 {
12453 new_return(2002);
12454 }
12455
12456 12 word numffcbindings=0;
12457
12458
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12459 {
12460
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12461 {
12462 200 numffcbindings++;
12463 200 }
12464 6132 }
12465
12466
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12467 {
12468 new_return(2003);
12469 }
12470
12471
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12472 {
12473
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12474 {
12475
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputw(it->first,f))
12476 {
12477 new_return(2004);
12478 }
12479
12480
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12481 {
12482 new_return(2005);
12483 }
12484
12485
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12486 {
12487 new_return(2006);
12488 }
12489 200 }
12490 6132 }
12491
12492 12 word numglobalbindings=0;
12493
12494
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12495 {
12496
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12497 {
12498 24 numglobalbindings++;
12499 24 }
12500 96 }
12501
12502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12503 {
12504 new_return(2007);
12505 }
12506
12507
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12508 {
12509
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12510 {
12511
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12512 {
12513 new_return(2008);
12514 }
12515
12516
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12517 {
12518 new_return(2009);
12519 }
12520
12521
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12522 {
12523 new_return(2010);
12524 }
12525 24 }
12526 96 }
12527
12528 12 word numitembindings=0;
12529
12530
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12531 {
12532
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12533 {
12534 24 numitembindings++;
12535 24 }
12536 3060 }
12537
12538
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12539 {
12540 new_return(2011);
12541 }
12542
12543
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12544 {
12545
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12546 {
12547
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12548 {
12549 new_return(2012);
12550 }
12551
12552
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12553 {
12554 new_return(2013);
12555 }
12556
12557
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12558 {
12559 new_return(2014);
12560 }
12561 24 }
12562 3060 }
12563
12564 //new script types
12565 //npc scripts
12566 12 word numnpcbindings=0;
12567
12568
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12569 {
12570
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12571 {
12572 numnpcbindings++;
12573 }
12574 3060 }
12575
12576
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12577 {
12578 new_return(2015);
12579 }
12580
12581
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12582 {
12583
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12584 {
12585 if(!p_iputw(it->first,f))
12586 {
12587 new_return(2016);
12588 }
12589
12590 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12591 {
12592 new_return(2017);
12593 }
12594
12595 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12596 {
12597 new_return(2018);
12598 }
12599 }
12600 3060 }
12601
12602 //lweapon
12603
12604 12 word numlwpnbindings=0;
12605
12606
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12607 {
12608
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12609 {
12610 numlwpnbindings++;
12611 }
12612 3060 }
12613
12614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12615 {
12616 new_return(2019);
12617 }
12618
12619
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12620 {
12621
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12622 {
12623 if(!p_iputw(it->first,f))
12624 {
12625 new_return(2020);
12626 }
12627
12628 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12629 {
12630 new_return(2021);
12631 }
12632
12633 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12634 {
12635 new_return(2022);
12636 }
12637 }
12638 3060 }
12639
12640 //////
12641
12642 //eweapon
12643
12644
12645 12 word numewpnbindings=0;
12646
12647
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12648 {
12649
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12650 {
12651 numewpnbindings++;
12652 }
12653 3060 }
12654
12655
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12656 {
12657 new_return(2023);
12658 }
12659
12660
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12661 {
12662
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12663 {
12664 if(!p_iputw(it->first,f))
12665 {
12666 new_return(2024);
12667 }
12668
12669 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12670 {
12671 new_return(2025);
12672 }
12673
12674 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12675 {
12676 new_return(2026);
12677 }
12678 }
12679 3060 }
12680
12681 //player scripts
12682 12 word numherobindings=0;
12683
12684
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12685 {
12686
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12687 {
12688 2 numherobindings++;
12689 2 }
12690 48 }
12691
12692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12693 {
12694 new_return(2027);
12695 }
12696
12697
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12698 {
12699
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12700 {
12701
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12702 {
12703 new_return(2028);
12704 }
12705
12706
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12707 {
12708 new_return(2029);
12709 }
12710
12711
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12712 {
12713 new_return(2030);
12714 }
12715 2 }
12716 48 }
12717
12718 //dmap scripts
12719 12 word numdmapbindings=0;
12720
12721
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12722 {
12723
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12724 {
12725 4 numdmapbindings++;
12726 4 }
12727 3060 }
12728
12729
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12730 {
12731 new_return(2031);
12732 }
12733
12734
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12735 {
12736
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12737 {
12738
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12739 {
12740 new_return(2032);
12741 }
12742
12743
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12744 {
12745 new_return(2033);
12746 }
12747
12748
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12749 {
12750 new_return(2034);
12751 }
12752 4 }
12753 3060 }
12754
12755 //screen scripts
12756 12 word numscreenbindings=0;
12757
12758
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12759 {
12760
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12761 {
12762 16 numscreenbindings++;
12763 16 }
12764 3060 }
12765
12766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12767 {
12768 new_return(2035);
12769 }
12770
12771
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12772 {
12773
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12774 {
12775
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputw(it->first,f))
12776 {
12777 new_return(2036);
12778 }
12779
12780
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12781 {
12782 new_return(2037);
12783 }
12784
12785
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12786 {
12787 new_return(2038);
12788 }
12789 16 }
12790 3060 }
12791 //item sprite scripts
12792 12 word numitemspritebindings=0;
12793
12794
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12795 {
12796
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12797 {
12798 numitemspritebindings++;
12799 }
12800 3060 }
12801
12802
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12803 {
12804 new_return(2039);
12805 }
12806
12807
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12808 {
12809
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12810 {
12811 if(!p_iputw(it->first,f))
12812 {
12813 new_return(2040);
12814 }
12815
12816 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12817 {
12818 new_return(2041);
12819 }
12820
12821 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12822 {
12823 new_return(2042);
12824 }
12825 }
12826 3060 }
12827
12828 //combo scripts
12829 12 word numcombobindings=0;
12830
12831
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12832 {
12833
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12834 {
12835 numcombobindings++;
12836 }
12837 6132 }
12838
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12839 {
12840 new_return(2043);
12841 }
12842
12843
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12844 {
12845
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12846 {
12847 if(!p_iputw(it->first,f))
12848 {
12849 new_return(2044);
12850 }
12851
12852 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12853 {
12854 new_return(2045);
12855 }
12856
12857 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12858 {
12859 new_return(2046);
12860 }
12861 }
12862 6132 }
12863 //subscreen scripts
12864 12 word numgenericbindings=0;
12865
12866
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12867 {
12868
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12869 {
12870 numgenericbindings++;
12871 }
12872 6132 }
12873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12874 {
12875 new_return(2043);
12876 }
12877
12878
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12879 {
12880
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12881 {
12882 if(!p_iputw(it->first,f))
12883 {
12884 new_return(2044);
12885 }
12886
12887 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12888 {
12889 new_return(2045);
12890 }
12891
12892 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12893 {
12894 new_return(2046);
12895 }
12896 }
12897 6132 }
12898
12899 //generic scripts
12900 12 word numsubscreenbindings=0;
12901
12902
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12903 {
12904
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12905 {
12906 numsubscreenbindings++;
12907 }
12908 3060 }
12909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12910 {
12911 new_return(2047);
12912 }
12913
12914
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12915 {
12916
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12917 {
12918 if(!p_iputw(it->first,f))
12919 {
12920 new_return(2048);
12921 }
12922
12923 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12924 {
12925 new_return(2049);
12926 }
12927
12928 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12929 {
12930 new_return(2050);
12931 }
12932 }
12933 3060 }
12934
12935
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12936 {
12937 6 section_size=writesize;
12938 6 }
12939 12 }
12940
12941
12942
12943
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12944 {
12945 char ebuf[80];
12946 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12947 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12948 }
12949
12950 6 new_return(0);
12951 //return 0; //this is just here to stomp the compiler from whining.
12952 //the irony is that it causes an "unreachable code" warning.
12953 6 }
12954
12955 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *Header, int32_t i, script_data **script)
12956 {
12957 //these are here to bypass compiler warnings about unused arguments
12958 46236 Header=Header;
12959 46236 i=i;
12960
12961
2/2
✓ Branch 0 taken 9494 times.
✓ Branch 1 taken 36742 times.
46236 size_t num_commands = (*script)->zasm_script ? (*script)->zasm_script->size : 0;
12962
12963
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputl(num_commands,f))
12964 {
12965 new_return(6);
12966 }
12967
12968 //Metadata
12969 46236 zasm_meta const& tmeta = (*script)->meta;
12970
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.zasm_v,f))
12971 {
12972 new_return(7);
12973 }
12974
12975
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.meta_v,f))
12976 {
12977 new_return(8);
12978 }
12979
12980
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.ffscript_v,f))
12981 {
12982 new_return(9);
12983 }
12984
12985
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc((int)tmeta.script_type,f))
12986 {
12987 new_return(10);
12988 }
12989
12990
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
12991 {
12992
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.run_idens[q],f))
12993 new_return(11);
12994 369888 }
12995
12996
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
12997 {
12998
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.run_types[q],f))
12999 {
13000 new_return(12);
13001 }
13002 369888 }
13003
13004
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc(tmeta.flags,f))
13005 {
13006 new_return(13);
13007 }
13008
13009
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v1,f))
13010 {
13011 new_return(14);
13012 }
13013
13014
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v2,f))
13015 {
13016 new_return(15);
13017 }
13018
13019
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v3,f))
13020 {
13021 new_return(16);
13022 }
13023
13024
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v4,f))
13025 {
13026 new_return(17);
13027 }
13028
13029
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putcstr(tmeta.script_name,f))
13030 new_return(18);
13031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46236 times.
46236 if(!p_putcstr(tmeta.author,f))
13032 new_return(19);
13033
2/2
✓ Branch 0 taken 462360 times.
✓ Branch 1 taken 46236 times.
508596 for(auto q = 0; q < 10; ++q)
13034 {
13035
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putcstr(tmeta.attributes[q],f))
13036 new_return(27);
13037
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putwstr(tmeta.attributes_help[q],f))
13038 new_return(28);
13039 462360 }
13040
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13041 {
13042
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attribytes[q],f))
13043 new_return(29);
13044
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attribytes_help[q],f))
13045 new_return(30);
13046 369888 }
13047
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13048 {
13049
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attrishorts[q],f))
13050 new_return(31);
13051
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13052 new_return(32);
13053 369888 }
13054
2/2
✓ Branch 0 taken 739776 times.
✓ Branch 1 taken 46236 times.
786012 for(auto q = 0; q < 16; ++q)
13055 {
13056
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putcstr(tmeta.usrflags[q],f))
13057 new_return(33);
13058
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putwstr(tmeta.usrflags_help[q],f))
13059 new_return(34);
13060 739776 }
13061
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13062 {
13063
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.initd[q],f))
13064 new_return(35);
13065
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.initd_help[q],f))
13066 new_return(36);
13067 369888 }
13068
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13069 {
13070
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.initd_type[q],f))
13071 new_return(37);
13072 369888 }
13073
13074
2/2
✓ Branch 0 taken 36742 times.
✓ Branch 1 taken 626442 times.
663184 for(int32_t j=0; j<num_commands; j++)
13075 {
13076 626442 auto& zas = (*script)->zasm_script->zasm[j];
13077
1/2
✓ Branch 0 taken 626442 times.
✗ Branch 1 not taken.
626442 if(!p_iputw(zas.command,f))
13078 {
13079 new_return(20);
13080 }
13081
13082
2/2
✓ Branch 0 taken 616948 times.
✓ Branch 1 taken 9494 times.
626442 if(zas.command==0xFFFF)
13083 {
13084 9494 break;
13085 }
13086 else
13087 {
13088
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg1,f))
13089 {
13090 new_return(21);
13091 }
13092
13093
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg2,f))
13094 {
13095 new_return(22);
13096 }
13097
13098
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(zas.arg3,f))
13099 {
13100 new_return(23);
13101 }
13102
13103 616948 uint32_t sz = 0;
13104
2/2
✓ Branch 0 taken 2770 times.
✓ Branch 1 taken 614178 times.
616948 if(zas.strptr)
13105 2770 sz = zas.strptr->size();
13106
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(sz,f))
13107 {
13108 new_return(23);
13109 }
13110
2/2
✓ Branch 0 taken 614178 times.
✓ Branch 1 taken 2770 times.
616948 if(sz)
13111 {
13112 2770 auto& str = *zas.strptr;
13113
2/2
✓ Branch 0 taken 222648 times.
✓ Branch 1 taken 2770 times.
225418 for(size_t q = 0; q < sz; ++q)
13114 {
13115
1/2
✓ Branch 0 taken 222648 times.
✗ Branch 1 not taken.
222648 if(!p_putc(str[q],f))
13116 {
13117 new_return(24);
13118 }
13119 222648 }
13120 2770 }
13121 616948 sz = 0;
13122
2/2
✓ Branch 0 taken 616834 times.
✓ Branch 1 taken 114 times.
616948 if(zas.vecptr)
13123 114 sz = zas.vecptr->size();
13124
1/2
✓ Branch 0 taken 616948 times.
✗ Branch 1 not taken.
616948 if(!p_iputl(sz,f))
13125 {
13126 new_return(25);
13127 }
13128
2/2
✓ Branch 0 taken 616834 times.
✓ Branch 1 taken 114 times.
616948 if(sz) //vector found
13129 {
13130 114 auto& vec = *zas.vecptr;
13131
2/2
✓ Branch 0 taken 850 times.
✓ Branch 1 taken 114 times.
964 for(size_t q = 0; q < sz; ++q)
13132 {
13133
1/2
✓ Branch 0 taken 850 times.
✗ Branch 1 not taken.
850 if(!p_iputl(vec[q],f))
13134 {
13135 new_return(26);
13136 }
13137 850 }
13138 114 }
13139 }
13140 616948 }
13141
13142 46236 new_return(0);
13143 }
13144
13145 extern SAMPLE customsfxdata[WAV_COUNT];
13146 extern uint8_t customsfxflag[WAV_COUNT>>3];
13147
13148 6 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13149 {
13150 //these are here to bypass compiler warnings about unused arguments
13151 6 Header=Header;
13152
13153 6 dword section_id=ID_SFX;
13154 6 dword section_version=V_SFX;
13155 6 dword section_cversion=CV_SFX;
13156 6 dword section_size=0;
13157
13158 //section id
13159
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13160 {
13161 new_return(1);
13162 }
13163
13164 //section version info
13165
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13166 {
13167 new_return(2);
13168 }
13169
13170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13171 {
13172 new_return(3);
13173 }
13174
13175
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13176 {
13177 12 fake_pack_writing=(writecycle==0);
13178
13179 //section size
13180
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13181 {
13182 new_return(4);
13183 }
13184
13185 12 writesize=0;
13186
13187
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int32_t i=0; i<WAV_COUNT>>3; i++)
13188 {
13189
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(customsfxflag[i],f))
13190 {
13191 new_return(5);
13192 }
13193 384 }
13194
13195
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13196 {
13197
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13198 2240 continue;
13199
13200
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!pfwrite(sfx_string[i], 36, f))
13201 {
13202 new_return(5);
13203 }
13204 820 }
13205
13206
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13207 {
13208
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13209 2240 continue;
13210
13211
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].bits,f))
13212 {
13213 new_return(5);
13214 }
13215
13216
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].stereo,f))
13217 {
13218 new_return(6);
13219 }
13220
13221
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].freq,f))
13222 {
13223 new_return(7);
13224 }
13225
13226
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].priority,f))
13227 {
13228 new_return(8);
13229 }
13230
13231
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].len,f))
13232 {
13233 new_return(9);
13234 }
13235
13236
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_start,f))
13237 {
13238 new_return(10);
13239 }
13240
13241
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_end,f))
13242 {
13243 new_return(11);
13244 }
13245
13246
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].param,f))
13247 {
13248 new_return(12);
13249 }
13250
13251 //de-endianfy the data
13252 820 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
13253
13254
2/2
✓ Branch 0 taken 18594894 times.
✓ Branch 1 taken 820 times.
18595714 for(int32_t j=0; j<wordstowrite; j++)
13255 {
13256
1/2
✓ Branch 0 taken 18594894 times.
✗ Branch 1 not taken.
18594894 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
13257 {
13258 new_return(13);
13259 }
13260 18594894 }
13261 820 }
13262
13263
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13264 {
13265 6 section_size=writesize;
13266 6 }
13267 12 }
13268
13269
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13270 {
13271 char ebuf[80];
13272 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13273 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13274 }
13275
13276 6 new_return(0);
13277 }
13278
13279 6 int32_t writeinitdata(PACKFILE *f, zquestheader *)
13280 {
13281 6 dword section_id=ID_INITDATA;
13282 6 dword section_version=V_INITDATA;
13283 6 dword section_cversion=CV_INITDATA;
13284 6 dword section_size = 0;
13285
13286 6 zinit.last_map=Map.getCurrMap();
13287 6 zinit.last_screen=Map.getCurrScr();
13288 6 zinit.normalize();
13289
13290 //section id
13291
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13292 {
13293 new_return(1);
13294 }
13295
13296 //section version info
13297
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13298 {
13299 new_return(2);
13300 }
13301
13302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13303 {
13304 new_return(3);
13305 }
13306
13307 //TODO
13308
13309
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13310 {
13311 12 fake_pack_writing=(writecycle==0);
13312
13313 //section size
13314
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13315 new_return(4);
13316
13317 12 writesize=0;
13318
13319
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int q = 0; q < MAXITEMS/8; ++q)
13320
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(zinit.items[q], f))
13321 new_return(5);
13322
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(int q = 0; q < MAXLEVELS/8; ++q)
13323 {
13324
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.map[q], f))
13325 new_return(6);
13326
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.compass[q], f))
13327 new_return(7);
13328
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.boss_key[q], f))
13329 new_return(8);
13330
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.mcguffin[q], f))
13331 new_return(9);
13332 768 }
13333
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbvec(zinit.level_keys, f))
13334 new_return(10);
13335
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(MAX_COUNTERS,f))
13336 new_return(11);
13337
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13338
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.counter[q],f))
13339 new_return(12);
13340
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13341
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.mcounter[q],f))
13342 new_return(13);
13343
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.bomb_ratio,f))
13344 new_return(14);
13345
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp,f))
13346 new_return(15);
13347
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp_per_hc,f))
13348 new_return(16);
13349
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.cont_heart,f))
13350 new_return(17);
13351
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hp_per_heart,f))
13352 new_return(18);
13353
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magic_per_block,f))
13354 new_return(19);
13355
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_damage_multiplier,f))
13356 new_return(20);
13357
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.ene_damage_multiplier,f))
13358 new_return(21);
13359
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_type,f))
13360 new_return(22);
13361
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_arg,f))
13362 new_return(23);
13363
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_percent,f))
13364 new_return(24);
13365
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.def_lightrad,f))
13366 new_return(25);
13367
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.transdark_percent,f))
13368 new_return(26);
13369
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.darkcol,f))
13370 new_return(27);
13371
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_x,f))
13372 new_return(28);
13373
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_y,f))
13374 new_return(29);
13375
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_xofs,f))
13376 new_return(30);
13377
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_yofs,f))
13378 new_return(31);
13379
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_color,f))
13380 new_return(32);
13381
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_1_color,f))
13382 new_return(33);
13383
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_2_color,f))
13384 new_return(34);
13385
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_flags,f))
13386 new_return(35);
13387
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.flags,f))
13388 new_return(36);
13389
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_map,f))
13390 new_return(37);
13391
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_screen,f))
13392 new_return(38);
13393
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_x,f))
13394 new_return(39);
13395
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_y,f))
13396 new_return(40);
13397
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_is_offset,f))
13398 new_return(41);
13399
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_speed,f))
13400 new_return(42);
13401
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.gravity,f))
13402 new_return(43);
13403
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.swimgravity,f))
13404 new_return(44);
13405
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.terminalv,f))
13406 new_return(45);
13407
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_speed,f))
13408 new_return(46);
13409
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_mult,f))
13410 new_return(47);
13411
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_div,f))
13412 new_return(48);
13413
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimUpStep,f))
13414 new_return(49);
13415
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimSideStep,f))
13416 new_return(50);
13417
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimDownStep,f))
13418 new_return(51);
13419
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.exitWaterJump,f))
13420 new_return(52);
13421
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroStep,f))
13422 new_return(53);
13423
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.heroAnimationStyle,f))
13424 new_return(54);
13425
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.jump_hero_layer_threshold,f))
13426 new_return(55);
13427
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.bunny_ltm,f))
13428 new_return(56);
13429
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.start_dmap,f))
13430 new_return(57);
13431
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.subscrSpeed,f))
13432 new_return(58);
13433
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.switchhookstyle,f))
13434 new_return(59);
13435
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magicdrainrate,f))
13436 new_return(60);
13437
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputzf(zinit.shove_offset,f))
13438 new_return(61);
13439
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.gen_doscript, f))
13440 new_return(62);
13441
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_exitState, f))
13442 new_return(63);
13443
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_reloadState, f))
13444 new_return(64);
13445
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_initd, f))
13446 new_return(65);
13447
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_eventstate, f))
13448 new_return(66);
13449
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_data, f))
13450 new_return(67);
13451
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.screen_data, f))
13452 new_return(68);
13453
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickerspeed, f))
13454 new_return(69);
13455
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickercolor, f))
13456 new_return(70);
13457
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickertransp, f))
13458 new_return(71);
13459
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputzf(zinit.air_drag, f))
13460 new_return(72);
13461
13462
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13463 {
13464 6 section_size=writesize;
13465 6 }
13466 12 }
13467
13468
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13469 {
13470 char ebuf[80];
13471 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13472 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13473 }
13474
13475 6 new_return(0);
13476 }
13477
13478 6 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
13479 {
13480 //these are here to bypass compiler warnings about unused arguments
13481 6 Header=Header;
13482
13483 6 dword section_id=ID_ITEMDROPSETS;
13484 6 dword section_version=V_ITEMDROPSETS;
13485 6 dword section_cversion=CV_ITEMDROPSETS;
13486 // dword section_size=0;
13487 6 dword section_size = 0;
13488 6 word num_item_drop_sets=count_item_drop_sets();
13489
13490 //section id
13491
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13492 {
13493 new_return(1);
13494 }
13495
13496 //section version info
13497
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13498 {
13499 new_return(2);
13500 }
13501
13502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13503 {
13504 new_return(3);
13505 }
13506
13507
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13508 {
13509 12 fake_pack_writing=(writecycle==0);
13510
13511 //section size
13512
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13513 {
13514 new_return(4);
13515 }
13516
13517 12 writesize=0;
13518
13519 //finally... section data
13520
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_item_drop_sets,f))
13521 {
13522 new_return(5);
13523 }
13524
13525
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 12 times.
170 for(int32_t i=0; i<num_item_drop_sets; i++)
13526 {
13527
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
13528 {
13529 new_return(6);
13530 }
13531
13532
2/2
✓ Branch 0 taken 1580 times.
✓ Branch 1 taken 158 times.
1738 for(int32_t j=0; j<10; ++j)
13533 {
13534
1/2
✓ Branch 0 taken 1580 times.
✗ Branch 1 not taken.
1580 if(!p_iputw(item_drop_sets[i].item[j],f))
13535 {
13536 new_return(7);
13537 }
13538 1580 }
13539
13540
2/2
✓ Branch 0 taken 1738 times.
✓ Branch 1 taken 158 times.
1896 for(int32_t j=0; j<11; ++j)
13541 {
13542
1/2
✓ Branch 0 taken 1738 times.
✗ Branch 1 not taken.
1738 if(!p_iputw(item_drop_sets[i].chance[j],f))
13543 {
13544 new_return(8);
13545 }
13546 1738 }
13547 158 }
13548
13549
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13550 {
13551 6 section_size=writesize;
13552 6 }
13553 12 }
13554
13555
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13556 {
13557 char ebuf[80];
13558 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13559 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13560 }
13561
13562 6 new_return(0);
13563 }
13564
13565 6 int32_t writefavorites(PACKFILE *f, zquestheader*)
13566 {
13567 6 dword section_id=ID_FAVORITES;
13568 6 dword section_version=V_FAVORITES;
13569 6 dword section_cversion=CV_FAVORITES;
13570 6 dword section_size = 0;
13571
13572 //section id
13573
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13574 {
13575 new_return(1);
13576 }
13577
13578 //section version info
13579
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13580 {
13581 new_return(2);
13582 }
13583
13584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13585 {
13586 new_return(3);
13587 }
13588
13589
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13590 {
13591 12 fake_pack_writing=(writecycle==0);
13592
13593 //section size
13594
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13595 new_return(4);
13596
13597 12 writesize=0;
13598
13599
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
13600 new_return(16);
13601
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
13602 new_return(17);
13603
13604 12 word favcmb_cnt = 0;
13605
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14918 times.
14922 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
13606
2/2
✓ Branch 0 taken 14910 times.
✓ Branch 1 taken 8 times.
14918 if(favorite_combos[q] != -1)
13607 {
13608 8 favcmb_cnt = q+1;
13609 8 break;
13610 }
13611
13612
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
13613 new_return(5);
13614
13615
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 12 times.
222 for(int i=0; i<favcmb_cnt; ++i)
13616 {
13617
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_putc(favorite_combo_modes[i], f))
13618 new_return(6);
13619
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_iputl(favorite_combos[i], f))
13620 new_return(7);
13621 210 }
13622
13623
13624 12 word max_combo_cols = MAX_COMBO_COLS;
13625
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_combo_cols,f))
13626 new_return(9);
13627
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int q = 0; q < max_combo_cols; ++q)
13628 {
13629
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(First[q],f))
13630 new_return(10);
13631
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_alistpos[q],f))
13632 new_return(11);
13633
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_pool_listpos[q],f))
13634 new_return(12);
13635 48 }
13636 12 word max_mappages = MAX_MAPPAGE_BTNS;
13637
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_mappages,f))
13638 new_return(13);
13639
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 12 times.
120 for(int q = 0; q < max_mappages; ++q)
13640 {
13641
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].map,f))
13642 new_return(14);
13643
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].screen,f))
13644 new_return(15);
13645 108 }
13646
13647
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13648 {
13649 6 section_size=writesize;
13650 6 }
13651 12 }
13652
13653
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13654 {
13655 char ebuf[80];
13656 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13657 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13658 }
13659
13660 6 new_return(0);
13661 }
13662
13663 6 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
13664 {
13665
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!afname) afname = filename;
13666 6 reset_combo_animations();
13667 6 reset_combo_animations2();
13668 6 strcpy(header.id_str,QH_NEWIDSTR);
13669 6 header.zelda_version = ZELDA_VERSION;
13670 6 header.internal = INTERNAL_VERSION;
13671 6 header.data_flags[ZQ_TILES] = true;
13672 6 header.data_flags[ZQ_CHEATS2] = 1;
13673 6 header.build=VERSION_BUILD;
13674
13675
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 6 times.
1518 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
13676 {
13677 1512 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
13678 1512 }
13679
13680 char zinfofilename[2048];
13681 6 replace_extension(zinfofilename, afname, "zinfo", 2047);
13682
13683 6 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
13684 6 box_out("Saving Quest...");
13685 6 box_eol();
13686 6 box_eol();
13687
13688
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string tmp_filename = util::create_temp_file_path(filename);
13689
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
13690
13691
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!f)
13692 return 1;
13693
13694
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Header...");
13695
13696
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeheader(f,&header)!=0)
13697 return 2;
13698
13699
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13700
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13701
13702
13703
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(header.external_zinfo)
13704 {
13705 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
13706
13707 box_out("Writing ZInfo...");
13708 if(inf)
13709 {
13710 if(writezinfo(inf,ZI)!=0)
13711 return 2;
13712
13713 pack_fclose(inf);
13714 box_out("okay.");
13715 }
13716 else box_out(" ...file failure");
13717 box_eol();
13718 }
13719 else
13720 {
13721
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing ZInfo...");
13722
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writezinfo(f,ZI)!=0)
13723 return 2;
13724
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13725
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13726 }
13727
13728
13729
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Rules...");
13730
13731
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writerules(f,&header)!=0)
13732 return 3;
13733
13734
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13735
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13736
13737
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Strings...");
13738
13739
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
13740 return 4;
13741
13742
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13743
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13744
13745
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Doors...");
13746
13747
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedoorcombosets(f,&header)!=0)
13748 return 5;
13749
13750
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13751
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13752
13753
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing DMaps...");
13754
13755
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
13756 return 6;
13757
13758
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13759
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13760
13761
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Data...");
13762
13763
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemisc(f,&header)!=0)
13764 return 7;
13765
13766
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13767
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13768
13769
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Colors...");
13770
13771
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemisccolors(f,&header)!=0)
13772 return 8;
13773
13774
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13775
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13776
13777
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Game Icons...");
13778
13779
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writegameicons(f,&header)!=0)
13780 return 9;
13781
13782
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13783
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13784
13785
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Items...");
13786
13787
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeitems(f,&header)!=0)
13788 return 10;
13789
13790
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13791
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13792
13793
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Weapons...");
13794
13795
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeweapons(f,&header)!=0)
13796 return 11;
13797
13798
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13799
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13800
13801
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Maps...");
13802
13803
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemaps(f,&header)!=0)
13804 return 12;
13805
13806
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13807
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13808
13809
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combos...");
13810
13811
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
13812 return 13;
13813
13814
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13815
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13816
13817
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combo Aliases...");
13818
13819
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
13820 return 14;
13821
13822
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13823
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13824
13825
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Color Data...");
13826
13827
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
13828 return 15;
13829
13830
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13831
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13832
13833
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Tiles...");
13834
13835
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
13836 return 16;
13837
13838
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13839
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13840
13841
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing MIDIs...");
13842
13843
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemidis(f)!=0)
13844 return 17;
13845
13846
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13847
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13848
13849
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Cheat Codes...");
13850
13851
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecheats(f,&header)!=0)
13852 return 18;
13853
13854
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13855
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13856
13857
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Init. Data...");
13858
13859
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeinitdata(f,&header)!=0)
13860 return 19;
13861
13862
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13863
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13864
13865
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Guy Data...");
13866
13867
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeguys(f,&header)!=0)
13868 return 20;
13869
13870
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13871
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13872
13873
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Player Sprite Data...");
13874
13875
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeherosprites(f,&header)!=0)
13876 return 21;
13877
13878
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13879
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13880
13881
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Subscreen Data...");
13882
13883
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesubscreens(f,&header)!=0)
13884 return 22;
13885
13886
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13887
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13888
13889
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing FF Script Data...");
13890
13891
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeffscript(f,&header)!=0)
13892 return 23;
13893
13894
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13895
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13896
13897
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing SFX Data...");
13898
13899
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesfx(f,&header)!=0)
13900 return 24;
13901
13902
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13903
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13904
13905
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Item Drop Sets...");
13906
13907
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeitemdropsets(f, &header)!=0)
13908 return 25;
13909
13910
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13911
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13912
13913
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Favorite Combos...");
13914
13915
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writefavorites(f, &header)!=0)
13916 return 26;
13917
13918
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13919
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13920
13921
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 pack_fclose(f);
13922
13923
13924
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if(header.use_keyfile&&header.dirty_password)
13925 {
13926 char const* kfname = filename;
13927 char keyfilename[2048]={0};
13928 zprint2("Writing key files for '%s'\n", kfname, ".zpwd", ".zcheat");
13929
13930 char temp_pw[QSTPWD_LEN] = {0};
13931 uint ind = 0;
13932 for(char const* ext : {"key","zpwd","zcheat"})
13933 {
13934 replace_extension(keyfilename, kfname, ext, 2047);
13935 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
13936 char msg[80] = {0};
13937 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
13938 msg[78]=13;
13939 msg[79]=10;
13940 pfwrite(msg, 80, fp);
13941 p_iputw(header.zelda_version,fp);
13942 p_putc(header.build,fp);
13943 char const* pwd = header.password;
13944 if(ind == 2) //.zcheat, hashed pwd
13945 {
13946 char hashmap = 'Z';
13947 hashmap += 'Q';
13948 hashmap += 'U';
13949 hashmap += 'E';
13950 hashmap += 'S';
13951 hashmap += 'T';
13952 for ( int q = 0; q < QSTPWD_LEN; ++q )
13953 {
13954 temp_pw[q] = header.password[q];
13955 temp_pw[q] += hashmap;
13956 }
13957 pwd = temp_pw;
13958 }
13959 pfwrite(pwd, strlen(pwd), fp);
13960 pack_fclose(fp);
13961 ++ind;
13962 }
13963 }
13964
13965 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
13966 6 std::error_code ec;
13967
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::rename(tmp_filename, filename, ec);
13968
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ec)
13969 {
13970 al_trace("Error saving: %s\n", std::strerror(ec.value()));
13971 return ec.value();
13972 }
13973
13974
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
13975
13976 #ifdef __EMSCRIPTEN__
13977 em_sync_fs();
13978 #endif
13979
13980 6 return 0;
13981 6 }
13982
13983 // #ifdef _WIN32
13984 // static std::time_t to_time_t(FILETIME const& ft) {
13985 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
13986 // t -= 116444736000000000ull;
13987 // t /= 10000000u;
13988 // return static_cast<std::time_t>(t);
13989 // }
13990 // #else
13991 // #endif
13992 template<typename TP>
13993 4 static std::time_t to_time_t(TP tp) {
13994 using namespace std::chrono;
13995 4 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
13996 4 return system_clock::to_time_t(sctp);
13997 }
13998
13999 4 std::string get_time_last_modified_string(std::string path)
14000 {
14001
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 auto write_time = fs::last_write_time(path);
14002 // TODO: C++20 but not supported yet.
14003 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14004 4 std::time_t tt = to_time_t(write_time);
14005 4 std::tm *gmt = std::gmtime(&tt);
14006 4 std::stringstream buffer;
14007
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 buffer << std::put_time(gmt, "%Y-%m-%d");
14008
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 std::string formattedFileTime = buffer.str();
14009 4 return formattedFileTime;
14010
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 }
14011
14012 6 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14013 {
14014 // Always backup quest if it was last saved in a different version of the editor,
14015 // or if this a new file and is overwritting another qst file.
14016
10/16
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
6 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14017 {
14018 4 std::string backup_name;
14019
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 std::string last_mod = get_time_last_modified_string(filename);
14020
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (strlen(header.zelda_version_string) > 0)
14021 {
14022
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14023 4 }
14024 else
14025 {
14026 backup_name = fmt::format("{}", last_mod);
14027 }
14028
7/14
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
4 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14029
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 fs::path backup_path = fs::path("backups") / backup_fname;
14030
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if (!fs::exists(backup_path))
14031 {
14032
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 fs::create_directories(fs::path("backups"));
14033
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 if (fs::copy_file(filename, backup_path))
14034 {
14035
5/10
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
4 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14036 4 }
14037 else
14038 {
14039 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14040 }
14041 4 }
14042 4 }
14043
14044 6 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14045 6 fake_pack_writing = false;
14046
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(ret)
14047 {
14048 box_out("-- Error saving quest file! --");
14049 box_end(true);
14050 }
14051 6 else box_end(false);
14052 6 return ret;
14053 }
14054
14055 6 int32_t save_quest(const char *filename, bool timed_save)
14056 {
14057
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14058
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 bool compress=!(timed_save&&UncompressedAutoSaves);
14059 char ext1[5];
14060 6 ext1[0]=0;
14061
14062
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(timed_save)
14063 {
14064 sprintf(ext1, "qt");
14065 }
14066 else
14067 {
14068 6 sprintf(ext1, "qb");
14069 }
14070
14071
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(retention)
14072 {
14073 char backupname[2048];
14074 char backupname2[2048];
14075 char ext[12];
14076
14077 for(int32_t i=retention-1; i>0; --i)
14078 {
14079 sprintf(ext, "%s%d", ext1, i-1);
14080 replace_extension(backupname, filepath, ext, 2047);
14081
14082 if(exists(backupname))
14083 {
14084 sprintf(ext, "%s%d", ext1, i);
14085 replace_extension(backupname2, filepath, ext, 2047);
14086
14087 if(exists(backupname2))
14088 {
14089 remove(backupname2);
14090 }
14091
14092 rename(backupname, backupname2);
14093 }
14094 }
14095
14096 //don't do this if we're not saving to the same name -DD
14097 if(!timed_save && !strcmp(filepath, filename))
14098 {
14099 sprintf(ext, "%s%d", ext1, 0);
14100 replace_extension(backupname, filepath, ext, 2047);
14101 rename(filepath, backupname);
14102 }
14103 }
14104
14105 int32_t ret;
14106 6 ret = save_unencoded_quest(filename, compress, filename);
14107
14108 6 return ret;
14109 }
14110
14111 6 void center_zq_class_dialogs()
14112 {
14113 6 jwin_center_dialog(pwd_dlg);
14114 6 }
14115
14116 void zmap::prv_secrets(bool high16only)
14117 {
14118 mapscr *s = &prvscr;
14119 mapscr *t = prvlayers;
14120 int32_t ft=0;
14121
14122 for(int32_t i=0; i<176; i++)
14123 {
14124 bool putit;
14125
14126 if(!high16only)
14127 {
14128 for(int32_t j=-1; j<6; j++)
14129 {
14130 int32_t newflag = -1;
14131
14132 for(int32_t iter=0; iter<2; ++iter)
14133 {
14134 putit=true;
14135
14136 if(!t[j].valid)
14137 continue;
14138
14139 int32_t checkflag=combobuf[t[j].data[i]].flag;
14140
14141 if(iter==1)
14142 {
14143 checkflag=t[j].sflag[i];
14144 }
14145
14146 switch(checkflag)
14147 {
14148 case mfANYFIRE:
14149 ft=sBCANDLE;
14150 break;
14151
14152 case mfSTRONGFIRE:
14153 ft=sRCANDLE;
14154 break;
14155
14156 case mfMAGICFIRE:
14157 ft=sWANDFIRE;
14158 break;
14159
14160 case mfDIVINEFIRE:
14161 ft=sDIVINEFIRE;
14162 break;
14163
14164 case mfARROW:
14165 ft=sARROW;
14166 break;
14167
14168 case mfSARROW:
14169 ft=sSARROW;
14170 break;
14171
14172 case mfGARROW:
14173 ft=sGARROW;
14174 break;
14175
14176 case mfSBOMB:
14177 ft=sSBOMB;
14178 break;
14179
14180 case mfBOMB:
14181 ft=sBOMB;
14182 break;
14183
14184 case mfBRANG:
14185 ft=sBRANG;
14186 break;
14187
14188 case mfMBRANG:
14189 ft=sMBRANG;
14190 break;
14191
14192 case mfFBRANG:
14193 ft=sFBRANG;
14194 break;
14195
14196 case mfWANDMAGIC:
14197 ft=sWANDMAGIC;
14198 break;
14199
14200 case mfREFMAGIC:
14201 ft=sREFMAGIC;
14202 break;
14203
14204 case mfREFFIREBALL:
14205 ft=sREFFIREBALL;
14206 break;
14207
14208 case mfSWORD:
14209 ft=sSWORD;
14210 break;
14211
14212 case mfWSWORD:
14213 ft=sWSWORD;
14214 break;
14215
14216 case mfMSWORD:
14217 ft=sMSWORD;
14218 break;
14219
14220 case mfXSWORD:
14221 ft=sXSWORD;
14222 break;
14223
14224 case mfSWORDBEAM:
14225 ft=sSWORDBEAM;
14226 break;
14227
14228 case mfWSWORDBEAM:
14229 ft=sWSWORDBEAM;
14230 break;
14231
14232 case mfMSWORDBEAM:
14233 ft=sMSWORDBEAM;
14234 break;
14235
14236 case mfXSWORDBEAM:
14237 ft=sXSWORDBEAM;
14238 break;
14239
14240 case mfHOOKSHOT:
14241 ft=sHOOKSHOT;
14242 break;
14243
14244 case mfWAND:
14245 ft=sWAND;
14246 break;
14247
14248 case mfHAMMER:
14249 ft=sHAMMER;
14250 break;
14251
14252 case mfSTRIKE:
14253 ft=sSTRIKE;
14254 break;
14255
14256 default:
14257 putit = false;
14258 break;
14259 }
14260
14261 if(putit)
14262 {
14263 if(j==-1)
14264 {
14265 s->data[i] = s->secretcombo[ft];
14266 s->cset[i] = s->secretcset[ft];
14267 newflag = s->secretflag[ft];
14268 }
14269 else
14270 {
14271 t[j].data[i] = t[j].secretcombo[ft];
14272 t[j].cset[i] = t[j].secretcset[ft];
14273 newflag = t[j].secretflag[ft];
14274 }
14275 }
14276 }
14277
14278 if(newflag >-1)
14279 {
14280 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14281 }
14282 }
14283 }
14284
14285 //if(true)
14286 //{
14287 int32_t newflag = -1;
14288
14289 for(int32_t iter=0; iter<2; ++iter)
14290 {
14291 int32_t checkflag=combobuf[s->data[i]].flag;
14292
14293 if(iter==1)
14294 {
14295 checkflag=s->sflag[i];
14296 }
14297
14298 if((checkflag > 15)&&(checkflag < 32))
14299 {
14300 s->data[i] = s->secretcombo[(checkflag)-16+4];
14301 s->cset[i] = s->secretcset[(checkflag)-16+4];
14302 newflag = s->secretflag[(checkflag)-16+4];
14303 // putit = true;
14304 }
14305 }
14306
14307 if(newflag >-1) s->sflag[i] = newflag;
14308
14309 for(int32_t j=0; j<6; j++)
14310 {
14311 if(!t[j].valid) continue;
14312
14313 int32_t newflag2 = -1;
14314
14315 for(int32_t iter=0; iter<2; ++iter)
14316 {
14317 int32_t checkflag=combobuf[t[j].data[i]].flag;
14318
14319 if(iter==1)
14320 {
14321 checkflag=t[j].sflag[i];
14322 }
14323
14324 if((checkflag > 15)&&(checkflag < 32))
14325 {
14326 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
14327 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
14328 newflag2 = t[j].secretflag[(checkflag)-16+4];
14329 }
14330 }
14331
14332 if(newflag2 >-1) t[j].sflag[i] = newflag2;
14333 }
14334 }
14335
14336 //FFCs
14337 word num_ffcs = s->numFFC();
14338 for(word i=0; i<num_ffcs; ++i)
14339 {
14340 bool putit;
14341
14342 if(!high16only)
14343 {
14344 for(int32_t iter=0; iter<1; ++iter)
14345 {
14346 putit=true;
14347 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14348
14349 if(iter==1)
14350 {
14351 checkflag=s->sflag[i];
14352 }
14353
14354 switch(checkflag)
14355 {
14356 case mfANYFIRE:
14357 ft=sBCANDLE;
14358 break;
14359
14360 case mfSTRONGFIRE:
14361 ft=sRCANDLE;
14362 break;
14363
14364 case mfMAGICFIRE:
14365 ft=sWANDFIRE;
14366 break;
14367
14368 case mfDIVINEFIRE:
14369 ft=sDIVINEFIRE;
14370 break;
14371
14372 case mfARROW:
14373 ft=sARROW;
14374 break;
14375
14376 case mfSARROW:
14377 ft=sSARROW;
14378 break;
14379
14380 case mfGARROW:
14381 ft=sGARROW;
14382 break;
14383
14384 case mfSBOMB:
14385 ft=sSBOMB;
14386 break;
14387
14388 case mfBOMB:
14389 ft=sBOMB;
14390 break;
14391
14392 case mfBRANG:
14393 ft=sBRANG;
14394 break;
14395
14396 case mfMBRANG:
14397 ft=sMBRANG;
14398 break;
14399
14400 case mfFBRANG:
14401 ft=sFBRANG;
14402 break;
14403
14404 case mfWANDMAGIC:
14405 ft=sWANDMAGIC;
14406 break;
14407
14408 case mfREFMAGIC:
14409 ft=sREFMAGIC;
14410 break;
14411
14412 case mfREFFIREBALL:
14413 ft=sREFFIREBALL;
14414 break;
14415
14416 case mfSWORD:
14417 ft=sSWORD;
14418 break;
14419
14420 case mfWSWORD:
14421 ft=sWSWORD;
14422 break;
14423
14424 case mfMSWORD:
14425 ft=sMSWORD;
14426 break;
14427
14428 case mfXSWORD:
14429 ft=sXSWORD;
14430 break;
14431
14432 case mfSWORDBEAM:
14433 ft=sSWORDBEAM;
14434 break;
14435
14436 case mfWSWORDBEAM:
14437 ft=sWSWORDBEAM;
14438 break;
14439
14440 case mfMSWORDBEAM:
14441 ft=sMSWORDBEAM;
14442 break;
14443
14444 case mfXSWORDBEAM:
14445 ft=sXSWORDBEAM;
14446 break;
14447
14448 case mfHOOKSHOT:
14449 ft=sHOOKSHOT;
14450 break;
14451
14452 case mfWAND:
14453 ft=sWAND;
14454 break;
14455
14456 case mfHAMMER:
14457 ft=sHAMMER;
14458 break;
14459
14460 case mfSTRIKE:
14461 ft=sSTRIKE;
14462 break;
14463
14464 default:
14465 putit = false;
14466 break;
14467 }
14468
14469 if(putit)
14470 {
14471 s->ffcs[i].data = s->secretcombo[ft];
14472 s->ffcs[i].cset = s->secretcset[ft];
14473 }
14474 }
14475 }
14476
14477 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
14478 {
14479 for(int32_t iter=0; iter<1; ++iter)
14480 {
14481 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14482
14483 if(iter==1)
14484 {
14485 // FFCs can't have flags! Yet...
14486 }
14487
14488 if((checkflag > 15)&&(checkflag < 32))
14489 {
14490 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
14491 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
14492 }
14493 }
14494 }
14495 }
14496 }
14497